[tracker-miners/wip/carlosg/perf-squeeze: 3/16] libtracker-miner: Simplify URN getters



commit fb1a99cffa98229166a62957536c957a6dd7fc84
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sat Jul 4 12:57:05 2020 +0200

    libtracker-miner: Simplify URN getters
    
    We have one getter for the URN as contained in the update task,
    and another that pokes the filesystem, and resorts to querying
    otherwise.
    
    As we basically want to deal with folders here, and those get
    conveniently cached in the TrackerFileSystem, rely on the latter
    for all places where we need a folder URN.

 src/libtracker-miner/tracker-miner-fs.c        | 89 ++------------------------
 src/libtracker-miner/tracker-miner-fs.h        |  4 +-
 src/miners/fs/tracker-miner-files.c            | 14 ++--
 tests/libtracker-miner/tracker-miner-fs-test.c | 12 ++--
 4 files changed, 19 insertions(+), 100 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index 862e514b6..70464176e 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -1224,14 +1224,12 @@ sparql_buffer_task_finished_cb (GObject      *object,
 static UpdateProcessingTaskContext *
 update_processing_task_context_new (TrackerMiner         *miner,
                                     gint                  priority,
-                                    const gchar          *urn,
                                     GCancellable         *cancellable)
 {
        UpdateProcessingTaskContext *ctxt;
 
        ctxt = g_slice_new0 (UpdateProcessingTaskContext);
        ctxt->miner = miner;
-       ctxt->urn = g_strdup (urn);
        ctxt->priority = priority;
 
        if (cancellable) {
@@ -1244,8 +1242,6 @@ update_processing_task_context_new (TrackerMiner         *miner,
 static void
 update_processing_task_context_free (UpdateProcessingTaskContext *ctxt)
 {
-       g_free (ctxt->urn);
-
        if (ctxt->cancellable) {
                g_object_unref (ctxt->cancellable);
        }
@@ -1282,14 +1278,7 @@ on_signal_gtask_complete (GObject      *source,
        } else {
                fs->priv->total_files_notified++;
 
-               if (ctxt->urn) {
-                       /* The SPARQL builder will already contain the necessary
-                        * DELETE statements for the properties being updated */
-                       TRACKER_NOTE (MINER_FS_EVENTS, g_message ("Updating item '%s' with urn '%s'",
-                                                                 uri, ctxt->urn));
-               } else {
-                       TRACKER_NOTE (MINER_FS_EVENTS, g_message ("Creating new item '%s'", uri));
-               }
+               TRACKER_NOTE (MINER_FS_EVENTS, g_message ("Creating/updating item '%s'", uri));
 
                sparql_task = tracker_sparql_task_new_take_sparql_str (file, sparql);
        }
@@ -1354,7 +1343,6 @@ item_add_or_update (TrackerMinerFS *fs,
        GCancellable *cancellable;
        gboolean processing;
        TrackerTask *task;
-       const gchar *urn;
        gchar *uri;
        GTask *gtask;
 
@@ -1363,14 +1351,10 @@ item_add_or_update (TrackerMinerFS *fs,
        cancellable = g_cancellable_new ();
        g_object_ref (file);
 
-       urn = tracker_file_notifier_get_file_iri (fs->priv->file_notifier,
-                                                 file, FALSE);
-
        /* Create task and add it to the pool as a WAIT task (we need to extract
         * the file metadata and such) */
        ctxt = update_processing_task_context_new (TRACKER_MINER (fs),
                                                   priority,
-                                                  urn,
                                                   cancellable);
        task = tracker_task_new (file, ctxt,
                                 (GDestroyNotify) update_processing_task_context_free);
@@ -2507,66 +2491,7 @@ tracker_miner_fs_get_throttle (TrackerMinerFS *fs)
 }
 
 /**
- * tracker_miner_fs_get_urn:
- * @fs: a #TrackerMinerFS
- * @file: a #GFile obtained in #TrackerMinerFS::process-file
- *
- * If the item exists in the store, this function retrieves
- * the URN for a #GFile being currently processed.
-
- * If @file is not being currently processed by @fs, or doesn't
- * exist in the store yet, %NULL will be returned.
- *
- * Returns: (transfer none) (nullable): The URN containing the data associated to @file,
- *          or %NULL.
- *
- * Since: 0.8
- **/
-const gchar *
-tracker_miner_fs_get_urn (TrackerMinerFS *fs,
-                          GFile          *file)
-{
-       TrackerTask *task;
-
-       g_return_val_if_fail (TRACKER_IS_MINER_FS (fs), NULL);
-       g_return_val_if_fail (G_IS_FILE (file), NULL);
-
-       /* Check if found in currently processed data */
-       task = tracker_task_pool_find (fs->priv->task_pool, file);
-
-       if (!task) {
-               gchar *uri;
-
-               uri = g_file_get_uri (file);
-
-               g_critical ("File '%s' is not being currently processed, "
-                           "so the URN cannot be retrieved.", uri);
-               g_free (uri);
-
-               return NULL;
-       } else {
-               UpdateProcessingTaskContext *ctxt;
-
-               /* We are only storing the URN in the created/updated tasks */
-               ctxt = tracker_task_get_data (task);
-
-               if (!ctxt) {
-                       gchar *uri;
-
-                       uri = g_file_get_uri (file);
-                       g_critical ("File '%s' is being processed, but not as a "
-                                   "CREATED/UPDATED task, so cannot get URN",
-                                   uri);
-                       g_free (uri);
-                       return NULL;
-               }
-
-               return ctxt->urn;
-       }
-}
-
-/**
- * tracker_miner_fs_query_urn:
+ * tracker_miner_fs_get_folder_urn:
  * @fs: a #TrackerMinerFS
  * @file: a #GFile
  *
@@ -2575,19 +2500,19 @@ tracker_miner_fs_get_urn (TrackerMinerFS *fs,
 
  * If @file doesn't exist in the store yet, %NULL will be returned.
  *
- * Returns: (transfer full): A newly allocated string with the URN containing the data associated
+ * Returns: The URN containing the data associated
  *          to @file, or %NULL.
  *
  * Since: 0.10
  **/
-gchar *
-tracker_miner_fs_query_urn (TrackerMinerFS *fs,
-                            GFile          *file)
+const gchar *
+tracker_miner_fs_get_folder_urn (TrackerMinerFS *fs,
+                                GFile          *file)
 {
        g_return_val_if_fail (TRACKER_IS_MINER_FS (fs), NULL);
        g_return_val_if_fail (G_IS_FILE (file), NULL);
 
-       return g_strdup (tracker_file_notifier_get_file_iri (fs->priv->file_notifier, file, TRUE));
+       return tracker_file_notifier_get_file_iri (fs->priv->file_notifier, file, TRUE);
 }
 
 /**
diff --git a/src/libtracker-miner/tracker-miner-fs.h b/src/libtracker-miner/tracker-miner-fs.h
index 3fdb67414..adace7dd2 100644
--- a/src/libtracker-miner/tracker-miner-fs.h
+++ b/src/libtracker-miner/tracker-miner-fs.h
@@ -166,9 +166,7 @@ void                  tracker_miner_fs_notify_finish         (TrackerMinerFS  *f
                                                              GError          *error);
 
 /* URNs */
-const gchar          *tracker_miner_fs_get_urn               (TrackerMinerFS  *fs,
-                                                              GFile           *file);
-gchar                *tracker_miner_fs_query_urn             (TrackerMinerFS  *fs,
+const gchar          *tracker_miner_fs_get_folder_urn        (TrackerMinerFS  *fs,
                                                               GFile           *file);
 
 
diff --git a/src/miners/fs/tracker-miner-files.c b/src/miners/fs/tracker-miner-files.c
index a1139bdea..739a6f427 100644
--- a/src/miners/fs/tracker-miner-files.c
+++ b/src/miners/fs/tracker-miner-files.c
@@ -1956,7 +1956,7 @@ miner_files_add_to_datasource (TrackerMinerFiles *mf,
                root = tracker_indexing_tree_get_root (indexing_tree, file, NULL);
 
                if (root)
-                       root_urn = tracker_miner_fs_query_urn (TRACKER_MINER_FS (mf), root);
+                       root_urn = tracker_miner_fs_get_folder_urn (TRACKER_MINER_FS (mf), root);
 
                if (root_urn)
                        tracker_resource_set_uri (resource, "nie:dataSource", root_urn);
@@ -1995,7 +1995,7 @@ miner_files_create_folder_information_element (TrackerMinerFiles *miner,
        gchar *uri;
 
        /* Preserve URN for nfo:Folders */
-       urn = tracker_miner_fs_get_urn (TRACKER_MINER_FS (miner), file);
+       urn = tracker_miner_fs_get_folder_urn (TRACKER_MINER_FS (miner), file);
 
        resource = tracker_resource_new (urn);
        tracker_resource_set_string (resource, "nie:mimeType", mime_type);
@@ -2094,7 +2094,7 @@ process_file_cb (GObject      *object,
        TrackerResource *resource, *folder_resource = NULL;
        ProcessFileData *data;
        const gchar *mime_type, *graph;
-       gchar *parent_urn;
+       const gchar *parent_urn;
        gchar *delete_properties_sparql = NULL, *mount_point_sparql;
        GFileInfo *file_info;
        guint64 time_;
@@ -2164,13 +2164,11 @@ process_file_cb (GObject      *object,
        tracker_resource_add_uri (resource, "rdf:type", "nfo:FileDataObject");
 
        parent = g_file_get_parent (file);
-       parent_urn = tracker_miner_fs_query_urn (TRACKER_MINER_FS (data->miner), parent);
+       parent_urn = tracker_miner_fs_get_folder_urn (TRACKER_MINER_FS (data->miner), parent);
        g_object_unref (parent);
 
-       if (parent_urn) {
+       if (parent_urn)
                tracker_resource_set_uri (resource, "nfo:belongsToContainer", parent_urn);
-               g_free (parent_urn);
-       }
 
        tracker_resource_set_string (resource, "nfo:fileName",
                                     g_file_info_get_display_name (file_info));
@@ -2462,7 +2460,7 @@ miner_files_move_file (TrackerMinerFS *fs,
        /* Get new parent information */
        new_parent = g_file_get_parent (file);
        if (new_parent)
-               new_parent_iri = tracker_miner_fs_query_urn (fs, new_parent);
+               new_parent_iri = tracker_miner_fs_get_folder_urn (fs, new_parent);
        if (new_parent_iri)
                container_clause = g_strdup_printf ("; nfo:belongsToContainer <%s>", new_parent_iri);
 
diff --git a/tests/libtracker-miner/tracker-miner-fs-test.c b/tests/libtracker-miner/tracker-miner-fs-test.c
index 4fb81d894..7cbb42cf6 100644
--- a/tests/libtracker-miner/tracker-miner-fs-test.c
+++ b/tests/libtracker-miner/tracker-miner-fs-test.c
@@ -38,21 +38,20 @@ test_miner_process_file (TrackerMinerFS *miner,
        GFileInfo *info;
        GDateTime *modification_time;
        gchar *sparql, *str;
-       gchar *urn;
+       const gchar *urn;
        GFile *parent;
 
        ((TestMiner *) miner)->n_process_file++;
        info = g_file_query_info (file, "standard::*,time::*", 0, NULL, &error);
        g_assert_no_error (error);
 
-       urn = tracker_miner_fs_query_urn (miner, file);
-       if (g_strcmp0 (tracker_miner_fs_get_urn (miner, file), urn) != 0) {
+       urn = tracker_miner_fs_get_folder_urn (miner, file);
+       if (g_strcmp0 (tracker_miner_fs_get_folder_urn (miner, file), urn) != 0) {
                g_critical ("File %s did not get up to date URN",
                            g_file_get_uri (file));
        }
-       g_free (urn);
 
-       resource = tracker_resource_new (tracker_miner_fs_get_urn (miner, file));
+       resource = tracker_resource_new (tracker_miner_fs_get_folder_urn (miner, file));
 
        if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) {
                tracker_resource_add_uri (resource, "rdf:type", "nfo:Folder");
@@ -76,12 +75,11 @@ test_miner_process_file (TrackerMinerFS *miner,
        g_free (str);
 
        parent = g_file_get_parent (file);
-       urn = tracker_miner_fs_query_urn (miner, parent);
+       urn = tracker_miner_fs_get_folder_urn (miner, parent);
        g_object_unref (parent);
 
        if (urn) {
                tracker_resource_set_string (resource, "nfo:belongsToContainer", urn);
-               g_free (urn);
        }
 
        sparql = tracker_resource_print_sparql_update (resource, NULL, "Graph");


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