[tracker-miners/wip/carlosg/monitor-event-fixes: 1/3] libtracker-miner: Make it just possible to check a file for task existence




commit 60e980a0b37f50af92ebed754836b214b6636ef5
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sun Aug 9 14:13:10 2020 +0200

    libtracker-miner: Make it just possible to check a file for task existence
    
    Avoid TrackerTask look ups, all places that should deal with it should
    have it readily available. Reduce this API to returning a boolean saying
    whether there is *some* task.

 src/libtracker-miner/tracker-miner-fs.c  | 9 ++++++---
 src/libtracker-miner/tracker-task-pool.c | 8 ++++----
 src/libtracker-miner/tracker-task-pool.h | 2 +-
 3 files changed, 11 insertions(+), 8 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index ffe3ea835..349476c10 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -98,6 +98,7 @@ typedef struct {
        gint priority;
        GCancellable *cancellable;
        TrackerMiner *miner;
+       TrackerTask *task;
 } UpdateProcessingTaskContext;
 
 struct _TrackerMinerFSPrivate {
@@ -1233,6 +1234,8 @@ update_processing_task_context_new (TrackerMiner         *miner,
 static void
 update_processing_task_context_free (UpdateProcessingTaskContext *ctxt)
 {
+       g_clear_pointer (&ctxt->task, tracker_task_unref);
+
        if (ctxt->cancellable) {
                g_object_unref (ctxt->cancellable);
        }
@@ -1267,11 +1270,10 @@ on_signal_gtask_complete (GObject      *source,
        sparql = g_task_propagate_pointer (G_TASK (res), &error);
        g_object_unref (res);
 
-       task = tracker_task_pool_find (fs->priv->task_pool, file);
-       g_assert (task != NULL);
-
        ctxt = g_task_get_task_data (G_TASK (res));
        uri = g_file_get_uri (file);
+       task = ctxt->task;
+       g_assert (task != NULL);
 
        if (error) {
                g_message ("Could not process '%s': %s", uri, error->message);
@@ -1362,6 +1364,7 @@ item_add_or_update (TrackerMinerFS *fs,
 
        task = tracker_task_new (file, g_object_ref (gtask), g_object_unref);
 
+       ctxt->task = tracker_task_ref (task);
        tracker_task_pool_add (priv->task_pool, task);
        tracker_task_unref (task);
 
diff --git a/src/libtracker-miner/tracker-task-pool.c b/src/libtracker-miner/tracker-task-pool.c
index 8f4008c45..be3acb5d1 100644
--- a/src/libtracker-miner/tracker-task-pool.c
+++ b/src/libtracker-miner/tracker-task-pool.c
@@ -282,17 +282,17 @@ tracker_task_pool_foreach (TrackerTaskPool *pool,
        }
 }
 
-TrackerTask *
+gboolean
 tracker_task_pool_find (TrackerTaskPool *pool,
                         GFile           *file)
 {
        TrackerTaskPoolPrivate *priv;
 
-       g_return_val_if_fail (TRACKER_IS_TASK_POOL (pool), NULL);
-       g_return_val_if_fail (G_IS_FILE (file), NULL);
+       g_return_val_if_fail (TRACKER_IS_TASK_POOL (pool), FALSE);
+       g_return_val_if_fail (G_IS_FILE (file), FALSE);
 
        priv = tracker_task_pool_get_instance_private (pool);
-       return g_hash_table_lookup (priv->tasks, file);
+       return g_hash_table_contains (priv->tasks, file);
 }
 
 /* Task */
diff --git a/src/libtracker-miner/tracker-task-pool.h b/src/libtracker-miner/tracker-task-pool.h
index ea0f48769..8cb5f9d58 100644
--- a/src/libtracker-miner/tracker-task-pool.h
+++ b/src/libtracker-miner/tracker-task-pool.h
@@ -70,7 +70,7 @@ void     tracker_task_pool_foreach       (TrackerTaskPool *pool,
                                           GFunc            func,
                                           gpointer         user_data);
 
-TrackerTask * tracker_task_pool_find     (TrackerTaskPool *pool,
+gboolean tracker_task_pool_find          (TrackerTaskPool *pool,
                                           GFile           *file);
 
 /* Task */


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