[tracker] TrackerDecorator: Make _prepend_ids and _delete_ids singular



commit 5325c8fedfeaa34de7b9f33f697c3eaf7ac01a94
Author: Xavier Claessens <xavier claessens collabora co uk>
Date:   Mon Jan 27 18:15:23 2014 -0500

    TrackerDecorator: Make _prepend_ids and _delete_ids singular
    
    It is easier to pass ids one by one instead of creating a GArray.
    Also it will be needed when passing more info about the id in
    upcoming commit.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=719802

 src/libtracker-miner/tracker-decorator-fs.c |   35 ++++-------------
 src/libtracker-miner/tracker-decorator.c    |   55 ++++++++-------------------
 src/libtracker-miner/tracker-decorator.h    |   10 ++---
 3 files changed, 28 insertions(+), 72 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-decorator-fs.c b/src/libtracker-miner/tracker-decorator-fs.c
index 65557f4..ac8265d 100644
--- a/src/libtracker-miner/tracker-decorator-fs.c
+++ b/src/libtracker-miner/tracker-decorator-fs.c
@@ -75,21 +75,6 @@ tracker_decorator_fs_class_init (TrackerDecoratorFSClass *klass)
        g_type_class_add_private (object_class, sizeof (TrackerDecoratorFSPrivate));
 }
 
-static GArray *
-cursor_to_array (TrackerSparqlCursor *cursor)
-{
-       GArray *ids;
-
-       ids = g_array_new (FALSE, FALSE, sizeof (gint));
-
-       while (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
-               gint id = tracker_sparql_cursor_get_integer (cursor, 0);
-               g_array_append_val (ids, id);
-       }
-
-       return ids;
-}
-
 static void
 process_files_cb (GObject      *object,
                   GAsyncResult *result,
@@ -98,7 +83,6 @@ process_files_cb (GObject      *object,
        TrackerSparqlConnection *conn;
        TrackerSparqlCursor *cursor;
        GError *error = NULL;
-       GArray *ids;
 
        conn = TRACKER_SPARQL_CONNECTION (object);
        cursor = tracker_sparql_connection_query_finish (conn, result, &error);
@@ -109,13 +93,12 @@ process_files_cb (GObject      *object,
                return;
        }
 
-       ids = cursor_to_array (cursor);
+       while (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
+               gint id = tracker_sparql_cursor_get_integer (cursor, 0);
+               tracker_decorator_prepend_id (TRACKER_DECORATOR (user_data), id);
+       }
 
-       if (ids->len > 0)
-               tracker_decorator_prepend_ids (TRACKER_DECORATOR (user_data),
-                                              (gint *) ids->data, ids->len);
        g_object_unref (cursor);
-       g_array_unref (ids);
 }
 
 static void
@@ -126,7 +109,6 @@ remove_files_cb (GObject *object,
        TrackerSparqlConnection *conn;
        TrackerSparqlCursor *cursor;
        GError *error = NULL;
-       GArray *ids;
 
        conn = TRACKER_SPARQL_CONNECTION (object);
        cursor = tracker_sparql_connection_query_finish (conn, result, &error);
@@ -137,13 +119,12 @@ remove_files_cb (GObject *object,
                return;
        }
 
-       ids = cursor_to_array (cursor);
+       while (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
+               gint id = tracker_sparql_cursor_get_integer (cursor, 0);
+               tracker_decorator_delete_id (TRACKER_DECORATOR (user_data), id);
+       }
 
-       if (ids->len > 0)
-               tracker_decorator_delete_ids (TRACKER_DECORATOR (user_data),
-                                             (gint *) ids->data, ids->len);
        g_object_unref (cursor);
-       g_array_unref (ids);
 }
 
 static void
diff --git a/src/libtracker-miner/tracker-decorator.c b/src/libtracker-miner/tracker-decorator.c
index e1d5d64..9a8e7b6 100644
--- a/src/libtracker-miner/tracker-decorator.c
+++ b/src/libtracker-miner/tracker-decorator.c
@@ -1002,66 +1002,43 @@ tracker_decorator_get_n_items (TrackerDecorator *decorator)
 }
 
 /**
- * tracker_decorator_prepend_ids:
+ * tracker_decorator_prepend_id:
  * @decorator: a #TrackerDecorator.
- * @ids: an array of IDs.
- * @n_ids: size of @ids array.
+ * @id: an ID.
  *
- * Adds resources needing extended metadata extraction to the queue.
- * IDs parsed in @ids are based on the same IDs emitted by
- * tracker-store when the database is updated for consistency. For
- * details, see the GraphUpdated signal.
+ * Adds resource needing extended metadata extraction to the queue.
+ * @id is the same IDs emitted by tracker-store when the database is updated for
+ * consistency. For details, see the GraphUpdated signal.
  *
  * Since: 0.18
  **/
 void
-tracker_decorator_prepend_ids (TrackerDecorator *decorator,
-                               gint             *ids,
-                               gint              n_ids)
+tracker_decorator_prepend_id (TrackerDecorator *decorator,
+                              gint              id)
 {
-       gint i;
-
        g_return_if_fail (TRACKER_IS_DECORATOR (decorator));
-       g_return_if_fail (ids != NULL);
-       g_return_if_fail (n_ids >= 0);
 
-       /* Prepend in inverse order to preserve ordering */
-       for (i = n_ids; i >= 0; i--)
-               element_add (decorator, ids[i], TRUE);
+       element_add (decorator, id, TRUE);
 }
 
 /**
- * tracker_decorator_delete_ids:
+ * tracker_decorator_delete_id:
  * @decorator: a #TrackerDecorator.
- * @ids: an array of IDs.
- * @n_ids: size of @ids array.
+ * @id: an ID.
  *
- * Deletes resources needing extended metadata extraction from the
- * queue. IDs parsed in @ids are based on the same IDs emitted by
- * tracker-store when the database is updated for consistency. For
- * details, see the GraphUpdated signal.
+ * Deletes resource needing extended metadata extraction from the
+ * queue. @id is the same IDs emitted by tracker-store when the database is
+ * updated for consistency. For details, see the GraphUpdated signal.
  *
  * Since: 0.18
  **/
 void
-tracker_decorator_delete_ids (TrackerDecorator *decorator,
-                              gint             *ids,
-                              gint              n_ids)
+tracker_decorator_delete_id (TrackerDecorator *decorator,
+                             gint              id)
 {
-       TrackerDecoratorPrivate *priv;
-       gint i;
-
        g_return_if_fail (TRACKER_IS_DECORATOR (decorator));
-       g_return_if_fail (ids != NULL);
-       g_return_if_fail (n_ids > 0);
-
-       priv = decorator->priv;
-
-       if (priv->elem_queue->length == 0)
-               return;
 
-       for (i = 0; i < n_ids; i++)
-               element_remove_by_id (decorator, ids[i]);
+       element_remove_by_id (decorator, id);
 }
 
 static GList *
diff --git a/src/libtracker-miner/tracker-decorator.h b/src/libtracker-miner/tracker-decorator.h
index c320f4d..b32d0bd 100644
--- a/src/libtracker-miner/tracker-decorator.h
+++ b/src/libtracker-miner/tracker-decorator.h
@@ -73,12 +73,10 @@ const gchar * tracker_decorator_get_data_source   (TrackerDecorator     *decorat
 const gchar** tracker_decorator_get_class_names   (TrackerDecorator     *decorator);
 guint         tracker_decorator_get_n_items       (TrackerDecorator     *decorator);
 
-void          tracker_decorator_prepend_ids       (TrackerDecorator     *decorator,
-                                                   gint                 *ids,
-                                                   gint                  n_ids);
-void          tracker_decorator_delete_ids        (TrackerDecorator     *decorator,
-                                                   gint                 *ids,
-                                                   gint                  n_ids);
+void          tracker_decorator_prepend_id        (TrackerDecorator     *decorator,
+                                                   gint                  id);
+void          tracker_decorator_delete_id         (TrackerDecorator     *decorator,
+                                                   gint                  id);
 
 void          tracker_decorator_next              (TrackerDecorator     *decorator,
                                                    GCancellable         *cancellable,


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