[tracker/miner-fs-refactor: 118/127] libtracker-miner: Avoid frequent sync calls
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/miner-fs-refactor: 118/127] libtracker-miner: Avoid frequent sync calls
- Date: Mon, 5 Dec 2011 13:29:31 +0000 (UTC)
commit 969228f4f1b696ed03b33f87d8c0b19001343c2b
Author: Carlos Garnacho <carlos lanedo com>
Date: Mon Nov 28 13:32:50 2011 +0100
libtracker-miner: Avoid frequent sync calls
TrackerCrawler now is able to retrieve GFileInfos with a given
set of attributes, avoiding the need in TrackerFileNotifier
to g_file_query_info() when traversing the file tree returned
on ::directory-crawled.
src/libtracker-miner/tracker-crawler.c | 78 +++++++++++++++++++++++++-
src/libtracker-miner/tracker-crawler.h | 7 ++
src/libtracker-miner/tracker-file-notifier.c | 27 ++++-----
3 files changed, 94 insertions(+), 18 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-crawler.c b/src/libtracker-miner/tracker-crawler.c
index 1e08d94..fa36824 100644
--- a/src/libtracker-miner/tracker-crawler.c
+++ b/src/libtracker-miner/tracker-crawler.c
@@ -78,6 +78,8 @@ struct TrackerCrawlerPrivate {
gdouble throttle;
+ gchar *file_attributes;
+
gboolean recurse;
/* Statistics */
@@ -123,6 +125,7 @@ static void directory_root_info_free (DirectoryRootInfo *info);
static guint signals[LAST_SIGNAL] = { 0, };
+static GQuark file_info_quark = 0;
G_DEFINE_TYPE (TrackerCrawler, tracker_crawler, G_TYPE_OBJECT)
@@ -196,6 +199,8 @@ tracker_crawler_class_init (TrackerCrawlerClass *klass)
1, G_TYPE_BOOLEAN);
g_type_class_add_private (object_class, sizeof (TrackerCrawlerPrivate));
+
+ file_info_quark = g_quark_from_static_string ("tracker-crawler-file-info");
}
static void
@@ -230,6 +235,8 @@ crawler_finalize (GObject *object)
g_queue_foreach (priv->directories, (GFunc) directory_root_info_free, NULL);
g_queue_free (priv->directories);
+ g_free (priv->file_attributes);
+
G_OBJECT_CLASS (tracker_crawler_parent_class)->finalize (object);
}
@@ -365,7 +372,8 @@ directory_processing_data_add_child (DirectoryProcessingData *data,
static DirectoryRootInfo *
directory_root_info_new (GFile *file,
- gboolean recurse)
+ gboolean recurse,
+ gchar *file_attributes)
{
DirectoryRootInfo *info;
DirectoryProcessingData *dir_info;
@@ -378,6 +386,20 @@ directory_root_info_new (GFile *file,
info->tree = g_node_new (g_object_ref (file));
+ if (file_attributes) {
+ GFileInfo *file_info;
+
+ file_info = g_file_query_info (file,
+ file_attributes,
+ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+ NULL,
+ NULL);
+ g_object_set_qdata_full (G_OBJECT (file),
+ file_info_quark,
+ file_info,
+ (GDestroyNotify) g_object_unref);
+ }
+
/* Fill in the processing info for the root node */
dir_info = directory_processing_data_new (info->tree);
g_queue_push_tail (info->directory_processing_queue, dir_info);
@@ -714,6 +736,14 @@ file_enumerate_next_cb (GObject *object,
child = g_file_get_child (parent, child_name);
is_dir = g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY;
+ if (crawler->priv->file_attributes) {
+ /* Store the file info for future retrieval */
+ g_object_set_qdata_full (G_OBJECT (child),
+ file_info_quark,
+ g_object_ref (info),
+ (GDestroyNotify) g_object_unref);
+ }
+
directory_processing_data_add_child (ed->dir_info, child, is_dir);
g_object_unref (child);
@@ -784,16 +814,27 @@ file_enumerate_children (TrackerCrawler *crawler,
DirectoryProcessingData *dir_data)
{
EnumeratorData *ed;
+ gchar *attrs;
ed = enumerator_data_new (crawler, info, dir_data);
+ if (crawler->priv->file_attributes) {
+ attrs = g_strconcat (FILE_ATTRIBUTES ",",
+ crawler->priv->file_attributes,
+ NULL);
+ } else {
+ attrs = g_strdup (FILE_ATTRIBUTES);
+ }
+
g_file_enumerate_children_async (ed->dir_file,
- FILE_ATTRIBUTES,
+ attrs,
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
G_PRIORITY_LOW,
ed->cancellable,
file_enumerate_children_cb,
ed);
+
+ g_free (attrs);
}
gboolean
@@ -831,7 +872,7 @@ tracker_crawler_start (TrackerCrawler *crawler,
priv->is_running = TRUE;
priv->is_finished = FALSE;
- info = directory_root_info_new (file, recurse);
+ info = directory_root_info_new (file, recurse, priv->file_attributes);
g_queue_push_tail (priv->directories, info);
process_func_start (crawler);
@@ -933,3 +974,34 @@ tracker_crawler_set_throttle (TrackerCrawler *crawler,
crawler->priv->idle_id = idle_id;
}
}
+
+void
+tracker_crawler_set_file_attributes (TrackerCrawler *crawler,
+ const gchar *file_attributes)
+{
+ g_return_if_fail (TRACKER_IS_CRAWLER (crawler));
+
+ g_free (crawler->priv->file_attributes);
+ crawler->priv->file_attributes = g_strdup (file_attributes);
+}
+
+const gchar *
+tracker_crawler_get_file_attributes (TrackerCrawler *crawler)
+{
+ g_return_val_if_fail (TRACKER_IS_CRAWLER (crawler), NULL);
+
+ return crawler->priv->file_attributes;
+}
+
+GFileInfo *
+tracker_crawler_get_file_info (TrackerCrawler *crawler,
+ GFile *file)
+{
+ GFileInfo *info;
+
+ g_return_val_if_fail (TRACKER_IS_CRAWLER (crawler), NULL);
+ g_return_val_if_fail (G_IS_FILE (file), NULL);
+
+ info = g_object_get_qdata (G_OBJECT (file), file_info_quark);
+ return info;
+}
diff --git a/src/libtracker-miner/tracker-crawler.h b/src/libtracker-miner/tracker-crawler.h
index 79781fc..2bed372 100644
--- a/src/libtracker-miner/tracker-crawler.h
+++ b/src/libtracker-miner/tracker-crawler.h
@@ -80,6 +80,13 @@ void tracker_crawler_resume (TrackerCrawler *crawler);
void tracker_crawler_set_throttle (TrackerCrawler *crawler,
gdouble throttle);
+void tracker_crawler_set_file_attributes (TrackerCrawler *crawler,
+ const gchar *file_attributes);
+const gchar * tracker_crawler_get_file_attributes (TrackerCrawler *crawler);
+
+GFileInfo * tracker_crawler_get_file_info (TrackerCrawler *crawler,
+ GFile *file);
+
G_END_DECLS
#endif /* __LIBTRACKER_MINER_CRAWLER_H__ */
diff --git a/src/libtracker-miner/tracker-file-notifier.c b/src/libtracker-miner/tracker-file-notifier.c
index ad7ebf0..2093f0e 100644
--- a/src/libtracker-miner/tracker-file-notifier.c
+++ b/src/libtracker-miner/tracker-file-notifier.c
@@ -74,6 +74,13 @@ typedef struct {
guint stopped : 1;
} TrackerFileNotifierPrivate;
+typedef struct {
+ TrackerFileNotifier *notifier;
+ GNode *cur_parent_node;
+
+ /* Canonical copy from priv->file_system */
+ GFile *cur_parent;
+} DirectoryCrawledData;
static gboolean crawl_directories_start (TrackerFileNotifier *notifier);
@@ -270,14 +277,6 @@ file_notifier_traverse_tree (TrackerFileNotifier *notifier)
}
}
-typedef struct {
- TrackerFileNotifier *notifier;
- GNode *cur_parent_node;
-
- /* Canonical copy from priv->file_system */
- GFile *cur_parent;
-} DirectoryCrawledData;
-
static gboolean
file_notifier_add_node_foreach (GNode *node,
gpointer user_data)
@@ -300,12 +299,7 @@ file_notifier_add_node_foreach (GNode *node,
data->cur_parent = NULL;
}
- file_info = g_file_query_info (file,
- G_FILE_ATTRIBUTE_TIME_MODIFIED ","
- G_FILE_ATTRIBUTE_STANDARD_TYPE,
- G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
- NULL,
- NULL);
+ file_info = tracker_crawler_get_file_info (priv->crawler, file);
if (file_info) {
GFileType file_type;
@@ -327,7 +321,6 @@ file_notifier_add_node_foreach (GNode *node,
tracker_file_system_set_property (priv->file_system, canonical,
quark_property_filesystem_mtime,
time_ptr);
- g_object_unref (file_info);
}
return FALSE;
@@ -1211,6 +1204,10 @@ tracker_file_notifier_init (TrackerFileNotifier *notifier)
/* Set up crawler */
priv->crawler = tracker_crawler_new ();
+ tracker_crawler_set_file_attributes (priv->crawler,
+ G_FILE_ATTRIBUTE_TIME_MODIFIED ","
+ G_FILE_ATTRIBUTE_STANDARD_TYPE);
+
g_signal_connect (priv->crawler, "check-file",
G_CALLBACK (crawler_check_file_cb),
notifier);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]