[tracker/miner-fs-refactor: 72/101] libtracker-miner: Improve a bit reference counting on TrackerFileNotifier



commit 06593062dbc7155176b1de66f62a2ed01f31a200
Author: Carlos Garnacho <carlos lanedo com>
Date:   Tue Oct 4 12:34:20 2011 +0200

    libtracker-miner: Improve a bit reference counting on TrackerFileNotifier

 src/libtracker-miner/tracker-file-notifier.c |   28 +++++++++++-
 src/libtracker-miner/tracker-file-system.c   |   58 ++++++++-----------------
 2 files changed, 44 insertions(+), 42 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-file-notifier.c b/src/libtracker-miner/tracker-file-notifier.c
index c859520..e16c4cb 100644
--- a/src/libtracker-miner/tracker-file-notifier.c
+++ b/src/libtracker-miner/tracker-file-notifier.c
@@ -190,6 +190,14 @@ crawler_check_directory_contents_cb (TrackerCrawler *crawler,
 }
 
 static gboolean
+file_notifier_unref_files (GFile    *file,
+                           gpointer  user_data)
+{
+	g_object_unref (file);
+	return FALSE;
+}
+
+static gboolean
 file_notifier_traverse_tree_foreach (GFile    *file,
                                      gpointer  user_data)
 {
@@ -241,6 +249,12 @@ file_notifier_traverse_tree (TrackerFileNotifier *notifier)
 				      file_notifier_traverse_tree_foreach,
 				      notifier);
 
+	tracker_file_system_traverse (priv->file_system,
+				      priv->pending_index_roots->data,
+				      G_POST_ORDER,
+	                              file_notifier_unref_files,
+	                              NULL);
+
 	tracker_info ("Finished notifying files after %2.2f seconds",
 	              g_timer_elapsed (priv->timer, NULL));
 
@@ -292,7 +306,8 @@ file_notifier_add_node_foreach (GNode    *node,
 	                                     G_FILE_TYPE_UNKNOWN,
 	                                     data->cur_parent);
 	file_info = g_file_query_info (file,
-				       G_FILE_ATTRIBUTE_TIME_MODIFIED,
+	                               G_FILE_ATTRIBUTE_TIME_MODIFIED ","
+	                               G_FILE_ATTRIBUTE_STANDARD_TYPE,
 				       G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
 				       NULL,
 				       NULL);
@@ -318,6 +333,12 @@ file_notifier_add_node_foreach (GNode    *node,
 		tracker_file_system_set_property (priv->file_system, file,
 						  quark_property_filesystem_mtime,
 						  time_str);
+
+		if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY) {
+			/* Reference directories so they're always cached */
+			g_object_ref (file);
+		}
+
 		g_object_unref (file_info);
 	}
 
@@ -399,8 +420,9 @@ sparql_file_query_populate (TrackerFileNotifier *notifier,
 		tracker_file_system_set_property (priv->file_system, canonical,
 						  quark_property_store_mtime,
 						  g_strdup (mtime));
-
-		g_object_unref (file);
+		if (file != canonical) {
+			g_object_unref (file);
+		}
 	}
 }
 
diff --git a/src/libtracker-miner/tracker-file-system.c b/src/libtracker-miner/tracker-file-system.c
index 6a359e7..529fa53 100644
--- a/src/libtracker-miner/tracker-file-system.c
+++ b/src/libtracker-miner/tracker-file-system.c
@@ -81,22 +81,6 @@ file_node_data_free (FileNodeData *data,
 	g_slice_free (FileNodeData, data);
 }
 
-static void
-file_weak_ref_notify (gpointer  user_data,
-                      GObject  *prev_location)
-{
-	FileNodeData *data;
-	GNode *node;
-
-	node = user_data;
-	data = node->data;
-
-	g_assert (data->file == (GFile *) prev_location);
-
-	/* Delete node tree here */
-	file_node_data_free (data, NULL);
-}
-
 static FileNodeData *
 file_node_data_new (GFile     *file,
                     GFileType  file_type,
@@ -351,6 +335,25 @@ reparent_child_nodes (GNode *node,
 	}
 }
 
+static void
+file_weak_ref_notify (gpointer  user_data,
+                      GObject  *prev_location)
+{
+	FileNodeData *data;
+	GNode *node;
+
+	node = user_data;
+	data = node->data;
+
+	g_assert (data->file == (GFile *) prev_location);
+
+	reparent_child_nodes (node, node->parent);
+
+	/* Delete node tree here */
+	file_node_data_free (data, NULL);
+	g_node_destroy (node);
+}
+
 static GNode *
 file_system_get_node (TrackerFileSystem *file_system,
                       GFile             *file)
@@ -498,29 +501,6 @@ tracker_file_system_peek_parent (TrackerFileSystem *file_system,
 	return NULL;
 }
 
-#if 0
-void
-tracker_file_system_unref_file (TrackerFileSystem  *file_system,
-                                TrackerFile        *file)
-{
-	FileNodeData *data;
-	GNode *node;
-
-	g_return_if_fail (TRACKER_IS_FILE_SYSTEM (file_system));
-	g_return_if_fail (file != NULL);
-
-	node = (GNode *) file;
-	data = node->data;
-
-	if (g_atomic_int_dec_and_test (&data->ref_count)) {
-		reparent_child_nodes (node, node->parent);
-
-		g_assert (g_node_first_child (node) == NULL);
-		g_node_destroy (node);
-	}
-}
-#endif
-
 typedef struct {
 	TrackerFileSystemTraverseFunc func;
 	gpointer user_data;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]