[tracker/prioritized-crawling: 3/4] libtracker-miner: Obey the "priority" flag when adding files to processing queues



commit f5c764c7cf3ed5f192da0cab903c8ed47561d874
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Feb 13 00:34:40 2014 +0100

    libtracker-miner: Obey the "priority" flag when adding files to processing queues
    
    If a file belongs to a root directory with that flag set, it will get G_PRIORITY_HIGH
    at the time of processing the file in TrackerMinerFS queues. Also, make
    tracker_miner_fs_check_directory() use G_PRIORITY_HIGH, like check_file() does.

 src/libtracker-miner/tracker-miner-fs.c |   72 ++++++++++++++++++++-----------
 1 files changed, 47 insertions(+), 25 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index fc7a0da..1bf742e 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -2508,6 +2508,30 @@ cancel_writeback_task (TrackerMinerFS *fs,
        }
 }
 
+static gint
+miner_fs_get_queue_priority (TrackerMinerFS *fs,
+                             GFile          *file)
+{
+       TrackerDirectoryFlags flags;
+
+       tracker_indexing_tree_get_root (fs->priv->indexing_tree,
+                                       file, &flags);
+
+       return (flags & TRACKER_DIRECTORY_FLAG_PRIORITY) ?
+               G_PRIORITY_HIGH : G_PRIORITY_DEFAULT;
+}
+
+static void
+miner_fs_queue_file (TrackerMinerFS       *fs,
+                    TrackerPriorityQueue *item_queue,
+                    GFile                *file)
+{
+       gint priority;
+
+       priority = miner_fs_get_queue_priority (fs, file);
+       tracker_priority_queue_add (item_queue, g_object_ref (file), priority);
+}
+
 /* Checks previous created/updated/deleted/moved/writeback queues for
  * monitor events. Returns TRUE if the item should still
  * be added to the queue.
@@ -2634,9 +2658,7 @@ check_item_queues (TrackerMinerFS *fs,
                         */
                        g_debug ("  Found matching unhandled CREATED event "
                                 "for source file, merging both events together");
-                       tracker_priority_queue_add (fs->priv->items_created,
-                                                   g_object_ref (other_file),
-                                                   G_PRIORITY_DEFAULT);
+                       miner_fs_queue_file (fs, fs->priv->items_created, other_file);
 
                        return FALSE;
                }
@@ -2671,9 +2693,7 @@ file_notifier_file_created (TrackerFileNotifier  *notifier,
        TrackerMinerFS *fs = user_data;
 
        if (check_item_queues (fs, QUEUE_CREATED, file, NULL)) {
-               tracker_priority_queue_add (fs->priv->items_created,
-                                           g_object_ref (file),
-                                           G_PRIORITY_DEFAULT);
+               miner_fs_queue_file (fs, fs->priv->items_created, file);
                item_queue_handlers_set_up (fs);
        }
 }
@@ -2686,9 +2706,7 @@ file_notifier_file_deleted (TrackerFileNotifier  *notifier,
        TrackerMinerFS *fs = user_data;
 
        if (check_item_queues (fs, QUEUE_DELETED, file, NULL)) {
-               tracker_priority_queue_add (fs->priv->items_deleted,
-                                           g_object_ref (file),
-                                           G_PRIORITY_DEFAULT);
+               miner_fs_queue_file (fs, fs->priv->items_deleted, file);
                item_queue_handlers_set_up (fs);
        }
 }
@@ -2719,9 +2737,7 @@ file_notifier_file_updated (TrackerFileNotifier  *notifier,
                                            GINT_TO_POINTER (TRUE));
                }
 
-               tracker_priority_queue_add (fs->priv->items_updated,
-                                           g_object_ref (file),
-                                           G_PRIORITY_DEFAULT);
+               miner_fs_queue_file (fs, fs->priv->items_updated, file);
                item_queue_handlers_set_up (fs);
        }
 }
@@ -2735,9 +2751,12 @@ file_notifier_file_moved (TrackerFileNotifier *notifier,
        TrackerMinerFS *fs = user_data;
 
        if (check_item_queues (fs, QUEUE_MOVED, source, dest)) {
+               gint priority;
+
+               priority = miner_fs_get_queue_priority (fs, dest);
                tracker_priority_queue_add (fs->priv->items_moved,
                                            item_moved_data_new (dest, source),
-                                           G_PRIORITY_DEFAULT);
+                                           priority);
                item_queue_handlers_set_up (fs);
        }
 }
@@ -3041,9 +3060,7 @@ tracker_miner_fs_directory_remove_full (TrackerMinerFS *fs,
                         * to preserve remove_full() semantics.
                         */
                        trace_eq_push_tail ("DELETED", file, "on remove full");
-                       tracker_priority_queue_add (fs->priv->items_deleted,
-                                                   g_object_ref (file),
-                                                   G_PRIORITY_DEFAULT);
+                       miner_fs_queue_file (fs, fs->priv->items_deleted, file);
                        item_queue_handlers_set_up (fs);
                }
 
@@ -3087,9 +3104,8 @@ check_file_parents (TrackerMinerFS *fs,
 
        for (p = parents; p; p = p->next) {
                trace_eq_push_tail ("UPDATED", p->data, "checking file parents");
-               tracker_priority_queue_add (fs->priv->items_updated,
-                                           p->data,
-                                           G_PRIORITY_DEFAULT);
+               miner_fs_queue_file (fs, fs->priv->items_updated, p->data);
+               g_object_unref (p->data);
        }
 
        g_list_free (parents);
@@ -3313,16 +3329,22 @@ tracker_miner_fs_check_directory_with_priority (TrackerMinerFS *fs,
                 path);
 
        if (should_process) {
+               TrackerDirectoryFlags flags;
+
                if (check_parents && !check_file_parents (fs, file)) {
                        return;
                }
 
-               /* FIXME: Apply priority */
+               flags = TRACKER_DIRECTORY_FLAG_RECURSE |
+                       TRACKER_DIRECTORY_FLAG_CHECK_MTIME |
+                       TRACKER_DIRECTORY_FLAG_MONITOR;
+
+               /* Priorities run from positive to negative */
+               if (priority < G_PRIORITY_DEFAULT)
+                       flags |= TRACKER_DIRECTORY_FLAG_PRIORITY;
+
                tracker_indexing_tree_add (fs->priv->indexing_tree,
-                                          file,
-                                          TRACKER_DIRECTORY_FLAG_RECURSE |
-                                          TRACKER_DIRECTORY_FLAG_CHECK_MTIME |
-                                          TRACKER_DIRECTORY_FLAG_MONITOR);
+                                          file, flags);
        }
 
        g_free (path);
@@ -3346,7 +3368,7 @@ tracker_miner_fs_check_directory (TrackerMinerFS *fs,
                                   gboolean        check_parents)
 {
        tracker_miner_fs_check_directory_with_priority (fs, file,
-                                                       G_PRIORITY_DEFAULT,
+                                                       G_PRIORITY_HIGH,
                                                        check_parents);
 }
 


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