[tracker] TrackerDecorator: Query the rdf:type for each element in the queue



commit 927164da6f7d36a768a760b68e2ebf4d6abd4f58
Author: Xavier Claessens <xavier claessens collabora co uk>
Date:   Mon Jan 27 18:36:37 2014 -0500

    TrackerDecorator: Query the rdf:type for each element in the queue
    
    The type will be used in upcoming commits to sort the elem_queue by
    priority.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=719802

 src/libtracker-miner/tracker-decorator-fs.c |    8 ++++--
 src/libtracker-miner/tracker-decorator.c    |   28 ++++++++++++++++----------
 src/libtracker-miner/tracker-decorator.h    |    3 +-
 3 files changed, 24 insertions(+), 15 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-decorator-fs.c b/src/libtracker-miner/tracker-decorator-fs.c
index 8812aaa..d19d774 100644
--- a/src/libtracker-miner/tracker-decorator-fs.c
+++ b/src/libtracker-miner/tracker-decorator-fs.c
@@ -96,7 +96,8 @@ process_files_cb (GObject      *object,
 
        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);
+               gint class_name_id = tracker_sparql_cursor_get_integer (cursor, 1);
+               tracker_decorator_prepend_id (TRACKER_DECORATOR (user_data), id, class_name_id);
        }
 
        g_object_unref (cursor);
@@ -139,7 +140,7 @@ check_files (TrackerDecorator    *decorator,
        GString *query;
 
        data_source = tracker_decorator_get_data_source (decorator);
-       query = g_string_new ("SELECT tracker:id(?urn) { ?urn ");
+       query = g_string_new ("SELECT tracker:id(?urn) tracker:id(?type) { ?urn ");
 
        if (mount_point_urn) {
                g_string_append_printf (query,
@@ -147,7 +148,8 @@ check_files (TrackerDecorator    *decorator,
                                        mount_point_urn);
        }
 
-       g_string_append (query, " a nfo:FileDataObject . ");
+       g_string_append (query, " a nfo:FileDataObject ;"
+                               " a ?type .");
        g_string_append_printf (query,
                                "FILTER (! EXISTS { ?urn nie:dataSource <%s> } ",
                                data_source);
diff --git a/src/libtracker-miner/tracker-decorator.c b/src/libtracker-miner/tracker-decorator.c
index bd8747e..5cc99f7 100644
--- a/src/libtracker-miner/tracker-decorator.c
+++ b/src/libtracker-miner/tracker-decorator.c
@@ -55,6 +55,7 @@ struct _TrackerDecoratorInfo {
 struct _ElemNode {
        TrackerDecoratorInfo *info;
        gint id;
+       gint class_name_id;
 };
 
 struct _TrackerDecoratorPrivate {
@@ -188,6 +189,7 @@ decorator_update_state (TrackerDecorator *decorator,
 static void
 element_add (TrackerDecorator *decorator,
              gint              id,
+             gint              class_name_id,
              gboolean          prepend)
 {
        TrackerDecoratorPrivate *priv;
@@ -203,6 +205,7 @@ element_add (TrackerDecorator *decorator,
        first_elem = g_hash_table_size (priv->elems) == 0;
        node = g_new0 (ElemNode, 1);
        node->id = id;
+       node->class_name_id = class_name_id;
 
        if (prepend) {
                g_queue_push_head (priv->elem_queue, node);
@@ -566,7 +569,8 @@ handle_deletes (TrackerDecorator *decorator,
                        /* If only the decorator datasource is removed,
                         * re-process the file from scratch.
                         */
-                       element_add (decorator, subject, FALSE);
+                       /* FIXME: Can we know the class_name_id ? */
+                       element_add (decorator, subject, 0, FALSE);
                }
        }
 }
@@ -601,7 +605,7 @@ handle_updates (TrackerDecorator *decorator,
                                    &graph, &subject, &predicate, &object)) {
                if (predicate == priv->rdf_type_id &&
                    class_name_id_handled (decorator, object))
-                       element_add (decorator, subject, FALSE);
+                       element_add (decorator, subject, object, FALSE);
        }
 }
 
@@ -725,14 +729,13 @@ _tracker_decorator_query_append_rdf_type_filter (TrackerDecorator *decorator,
        if (!class_names || !*class_names)
                return;
 
-       g_string_append (query, "&& (");
+       g_string_append (query, "&& ?type IN (");
 
        while (class_names[i]) {
                if (i != 0)
-                       g_string_append (query, "||");
+                       g_string_append (query, ",");
 
-               g_string_append_printf (query, "EXISTS { ?urn a %s }",
-                                       class_names[i]);
+               g_string_append (query, class_names[i]);
                i++;
        }
 
@@ -759,7 +762,8 @@ query_elements_cb (GObject      *object,
 
        while (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
                gint id = tracker_sparql_cursor_get_integer (cursor, 0);
-               element_add (user_data, id, TRUE);
+               gint class_name_id = tracker_sparql_cursor_get_integer (cursor, 1);
+               element_add (user_data, id, class_name_id, TRUE);
        }
 
        g_object_unref (cursor);
@@ -806,8 +810,9 @@ tracker_decorator_started (TrackerMiner *miner)
 
        g_timer_start (priv->timer);
        data_source = tracker_decorator_get_data_source (decorator);
-       query = g_string_new ("SELECT tracker:id(?urn) { "
-                             "  ?urn a rdfs:Resource . ");
+       query = g_string_new ("SELECT tracker:id(?urn) tracker:id(?type) { "
+                             "  ?urn a rdfs:Resource ; "
+                             "       a ?type. ");
 
        g_string_append_printf (query,
                                "FILTER (! EXISTS { ?urn nie:dataSource <%s> } ",
@@ -991,11 +996,12 @@ tracker_decorator_get_n_items (TrackerDecorator *decorator)
  **/
 void
 tracker_decorator_prepend_id (TrackerDecorator *decorator,
-                              gint              id)
+                              gint              id,
+                              gint              class_name_id)
 {
        g_return_if_fail (TRACKER_IS_DECORATOR (decorator));
 
-       element_add (decorator, id, TRUE);
+       element_add (decorator, id, class_name_id, TRUE);
 }
 
 /**
diff --git a/src/libtracker-miner/tracker-decorator.h b/src/libtracker-miner/tracker-decorator.h
index 5677700..2d02bb6 100644
--- a/src/libtracker-miner/tracker-decorator.h
+++ b/src/libtracker-miner/tracker-decorator.h
@@ -74,7 +74,8 @@ const gchar** tracker_decorator_get_class_names   (TrackerDecorator     *decorat
 guint         tracker_decorator_get_n_items       (TrackerDecorator     *decorator);
 
 void          tracker_decorator_prepend_id        (TrackerDecorator     *decorator,
-                                                   gint                  id);
+                                                   gint                  id,
+                                                   gint                  class_name_id);
 void          tracker_decorator_delete_id         (TrackerDecorator     *decorator,
                                                    gint                  id);
 


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