[gnome-online-miners/sam/tracker3: 4/5] Organize data into content-based graphs




commit 159aee4f58d3d3352269270bdf9cb7fcf53c5ca8
Author: Sam Thursfield <sam afuera me uk>
Date:   Fri May 15 02:13:11 2020 +0200

    Organize data into content-based graphs
    
    Previously GOM used a graph per account and per resource but this
    cannot be done in Tracker 3.
    
    In Tracker 3, each graph is stored as a separate SQLite database
    and currently a maximum of ten graphs can be included in a single
    query due to SQLite's limitations.
    
    The new layout is modelled after how tracker-miner-fs uses graphs:
    we use a graph per content type (Contacts, Documents, Pictures),
    plus an extra graph to store accounts and folders/collections.

 src/gom-facebook-miner.c     | 12 +++---
 src/gom-flickr-miner.c       | 24 ++++++------
 src/gom-gdata-miner.c        | 31 ++++++++-------
 src/gom-media-server-miner.c | 10 ++---
 src/gom-miner.c              | 40 ++++++++++++++-----
 src/gom-miner.h              |  1 -
 src/gom-owncloud-miner.c     | 22 +++++++----
 src/gom-tracker.c            | 93 +++++++++++++++++++++-----------------------
 src/gom-tracker.h            | 14 ++++++-
 src/gom-zpj-miner.c          | 22 +++++------
 10 files changed, 150 insertions(+), 119 deletions(-)
---
diff --git a/src/gom-facebook-miner.c b/src/gom-facebook-miner.c
index ff42ca5..fc89096 100644
--- a/src/gom-facebook-miner.c
+++ b/src/gom-facebook-miner.c
@@ -70,7 +70,7 @@ account_miner_job_process_photo (GomAccountMinerJob *job,
     (connection,
      cancellable, error,
      &resource_exists,
-     datasource_urn, identifier,
+     TRACKER_PICTURES_GRAPH, identifier,
      "nfo:RemoteDataObject", class, NULL);
 
   if (*error != NULL)
@@ -239,7 +239,7 @@ account_miner_job_process_album (GomAccountMinerJob *job,
   gom_tracker_sparql_connection_insert_or_replace_triple
     (connection,
      cancellable, error,
-     datasource_urn, resource,
+     TRACKER_PICTURES_GRAPH, resource,
      "nie:url", album_link);
 
   if (*error != NULL)
@@ -248,7 +248,7 @@ account_miner_job_process_album (GomAccountMinerJob *job,
   gom_tracker_sparql_connection_insert_or_replace_triple
     (connection,
      cancellable, error,
-     datasource_urn, resource,
+     TRACKER_PICTURES_GRAPH, resource,
      "nie:description", album_description);
 
   if (*error != NULL)
@@ -257,7 +257,7 @@ account_miner_job_process_album (GomAccountMinerJob *job,
   gom_tracker_sparql_connection_insert_or_replace_triple
     (connection,
      cancellable, error,
-     datasource_urn, resource,
+     TRACKER_PICTURES_GRAPH, resource,
      "nie:title", album_name);
 
   if (*error != NULL)
@@ -274,7 +274,7 @@ account_miner_job_process_album (GomAccountMinerJob *job,
   gom_tracker_sparql_connection_insert_or_replace_triple
     (connection,
      cancellable, error,
-     datasource_urn, resource,
+     TRACKER_PICTURES_GRAPH, resource,
      "nco:creator", contact_resource);
   g_free (contact_resource);
 
@@ -284,7 +284,7 @@ account_miner_job_process_album (GomAccountMinerJob *job,
   gom_tracker_sparql_connection_insert_or_replace_triple
     (connection,
      cancellable, error,
-     datasource_urn, resource,
+     TRACKER_PICTURES_GRAPH, resource,
      "nie:contentCreated", album_created_time);
 
   if (*error != NULL)
diff --git a/src/gom-flickr-miner.c b/src/gom-flickr-miner.c
index 9ac338e..dc7349e 100644
--- a/src/gom-flickr-miner.c
+++ b/src/gom-flickr-miner.c
@@ -143,14 +143,14 @@ account_miner_job_process_entry (GomAccountMinerJob *job,
     (connection,
      cancellable, error,
      &resource_exists,
-     datasource_urn, identifier,
+     TRACKER_PICTURES_GRAPH, identifier,
      "nfo:RemoteDataObject", class, NULL);
 
   if (*error != NULL)
     goto out;
 
   gom_tracker_update_datasource (connection, datasource_urn,
-                                 resource_exists, identifier, resource,
+                                 resource_exists, TRACKER_PICTURES_GRAPH, resource,
                                  cancellable, error);
 
   if (*error != NULL)
@@ -166,7 +166,7 @@ account_miner_job_process_entry (GomAccountMinerJob *job,
       parent_resource_urn = gom_tracker_sparql_connection_ensure_resource
         (connection, cancellable, error,
          NULL,
-         datasource_urn, parent_identifier,
+         TRACKER_PICTURES_GRAPH, parent_identifier,
          "nfo:RemoteDataObject", "nfo:DataContainer", NULL);
       g_free (parent_identifier);
 
@@ -176,7 +176,7 @@ account_miner_job_process_entry (GomAccountMinerJob *job,
       gom_tracker_sparql_connection_insert_or_replace_triple
         (connection,
          cancellable, error,
-         datasource_urn, resource,
+         TRACKER_PICTURES_GRAPH, resource,
          "nie:isPartOf", parent_resource_urn);
       g_free (parent_resource_urn);
 
@@ -187,7 +187,7 @@ account_miner_job_process_entry (GomAccountMinerJob *job,
   gom_tracker_sparql_connection_insert_or_replace_triple
     (connection,
      cancellable, error,
-     datasource_urn, resource,
+     TRACKER_PICTURES_GRAPH, resource,
      "nie:title", grl_media_get_title (entry->media));
 
   if (*error != NULL)
@@ -202,7 +202,7 @@ account_miner_job_process_entry (GomAccountMinerJob *job,
   created_time = modification_date = grl_media_get_creation_date (entry->media);
   new_mtime = g_date_time_to_unix (modification_date);
   mtime_changed = gom_tracker_update_mtime (connection, new_mtime,
-                                            resource_exists, identifier, resource,
+                                            resource_exists, TRACKER_PICTURES_GRAPH, resource,
                                             cancellable, error);
 
   if (*error != NULL)
@@ -221,7 +221,7 @@ account_miner_job_process_entry (GomAccountMinerJob *job,
       gom_tracker_sparql_connection_insert_or_replace_triple
         (connection,
          cancellable, error,
-         datasource_urn, resource,
+         TRACKER_PICTURES_GRAPH, resource,
          "nie:contentCreated", date);
       g_free (date);
     }
@@ -233,7 +233,7 @@ account_miner_job_process_entry (GomAccountMinerJob *job,
   gom_tracker_sparql_connection_insert_or_replace_triple
     (connection,
      cancellable, error,
-     datasource_urn, resource,
+     TRACKER_PICTURES_GRAPH, resource,
      "nie:url", url);
 
   if (*error != NULL)
@@ -242,7 +242,7 @@ account_miner_job_process_entry (GomAccountMinerJob *job,
   gom_tracker_sparql_connection_insert_or_replace_triple
     (connection,
      cancellable, error,
-     datasource_urn, resource,
+     TRACKER_PICTURES_GRAPH, resource,
      "nie:description", grl_media_get_description (entry->media));
 
   if (*error != NULL)
@@ -254,7 +254,7 @@ account_miner_job_process_entry (GomAccountMinerJob *job,
       gom_tracker_sparql_connection_insert_or_replace_triple
         (connection,
          cancellable, error,
-         datasource_urn, resource,
+         TRACKER_PICTURES_GRAPH, resource,
          "nie:mimeType", mime);
       g_free (mime);
 
@@ -265,7 +265,7 @@ account_miner_job_process_entry (GomAccountMinerJob *job,
   contact_resource = gom_tracker_utils_ensure_contact_resource
     (connection,
      cancellable, error,
-     datasource_urn, grl_media_get_author (entry->media));
+     TRACKER_PICTURES_GRAPH, grl_media_get_author (entry->media));
 
   if (*error != NULL)
     goto out;
@@ -273,7 +273,7 @@ account_miner_job_process_entry (GomAccountMinerJob *job,
   gom_tracker_sparql_connection_insert_or_replace_triple
     (connection,
      cancellable, error,
-     datasource_urn, resource,
+     TRACKER_PICTURES_GRAPH, resource,
      "nco:creator", contact_resource);
   g_free (contact_resource);
 
diff --git a/src/gom-gdata-miner.c b/src/gom-gdata-miner.c
index 7872431..d0deb80 100644
--- a/src/gom-gdata-miner.c
+++ b/src/gom-gdata-miner.c
@@ -120,7 +120,7 @@ account_miner_job_process_entry (TrackerSparqlConnection *connection,
     (connection,
      cancellable, error,
      &resource_exists,
-     datasource_urn, identifier,
+     TRACKER_DOCUMENTS_GRAPH, identifier,
      "nfo:RemoteDataObject", class, NULL);
 
   if (*error != NULL)
@@ -187,7 +187,7 @@ account_miner_job_process_entry (TrackerSparqlConnection *connection,
       parent_resource_urn = gom_tracker_sparql_connection_ensure_resource
         (connection, cancellable, error,
          NULL,
-         datasource_urn, parent_resource_id,
+         GOM_GRAPH, parent_resource_id,
          "nfo:RemoteDataObject", "nfo:DataContainer", NULL);
       g_free (parent_resource_id);
 
@@ -219,7 +219,7 @@ account_miner_job_process_entry (TrackerSparqlConnection *connection,
   gom_tracker_sparql_connection_toggle_favorite
     (connection,
      cancellable, error,
-     resource, starred);
+     TRACKER_PICTURES_GRAPH, resource, starred);
 
   if (*error != NULL)
     goto out;
@@ -400,14 +400,14 @@ account_miner_job_process_photo (TrackerSparqlConnection *connection,
     (connection,
      cancellable, error,
      &resource_exists,
-     datasource_urn, identifier,
+     TRACKER_PICTURES_GRAPH, identifier,
      "nfo:RemoteDataObject", "nmm:Photo", NULL);
 
   if (*error != NULL)
     goto out;
 
   gom_tracker_update_datasource (connection, datasource_urn,
-                                 resource_exists, identifier, resource,
+                                 resource_exists, TRACKER_PICTURES_GRAPH, resource,
                                  cancellable, error);
   if (*error != NULL)
     goto out;
@@ -566,6 +566,7 @@ account_miner_job_process_photo (TrackerSparqlConnection *connection,
       equipment_resource = gom_tracker_utils_ensure_equipment_resource (connection,
                                                                         cancellable,
                                                                         error,
+                                                                        TRACKER_PICTURES_GRAPH,
                                                                         make,
                                                                         model);
 
@@ -665,7 +666,7 @@ account_miner_job_process_album (TrackerSparqlConnection *connection,
     (connection,
      cancellable, error,
      &resource_exists,
-     datasource_urn, identifier,
+     TRACKER_PICTURES_GRAPH, identifier,
      "nfo:RemoteDataObject", "nfo:DataContainer",
      NULL);
 
@@ -674,7 +675,7 @@ account_miner_job_process_album (TrackerSparqlConnection *connection,
 
   gom_tracker_update_datasource
     (connection, datasource_urn,
-     resource_exists, identifier, resource,
+     resource_exists, TRACKER_PICTURES_GRAPH, resource,
      cancellable, error);
 
   if (*error != NULL)
@@ -685,7 +686,7 @@ account_miner_job_process_album (TrackerSparqlConnection *connection,
    */
   new_mtime = gdata_entry_get_updated (GDATA_ENTRY (album));
   mtime_changed = gom_tracker_update_mtime (connection, new_mtime,
-                                            resource_exists, identifier, resource,
+                                            resource_exists, TRACKER_PICTURES_GRAPH, resource,
                                             cancellable, error);
 
   if (*error != NULL)
@@ -703,7 +704,7 @@ account_miner_job_process_album (TrackerSparqlConnection *connection,
   gom_tracker_sparql_connection_insert_or_replace_triple
     (connection,
      cancellable, error,
-     datasource_urn, resource,
+     TRACKER_PICTURES_GRAPH, resource,
      "nie:url", alternate_uri);
 
   if (*error != NULL)
@@ -713,7 +714,7 @@ account_miner_job_process_album (TrackerSparqlConnection *connection,
   gom_tracker_sparql_connection_insert_or_replace_triple
     (connection,
      cancellable, error,
-     datasource_urn, resource,
+     TRACKER_PICTURES_GRAPH, resource,
      "nie:description", summary);
 
   if (*error != NULL)
@@ -723,7 +724,7 @@ account_miner_job_process_album (TrackerSparqlConnection *connection,
   gom_tracker_sparql_connection_insert_or_replace_triple
     (connection,
      cancellable, error,
-     datasource_urn, resource,
+     TRACKER_PICTURES_GRAPH, resource,
      "nie:title", title);
 
   if (*error != NULL)
@@ -743,7 +744,7 @@ account_miner_job_process_album (TrackerSparqlConnection *connection,
   gom_tracker_sparql_connection_insert_or_replace_triple
     (connection,
      cancellable, error,
-     datasource_urn, resource,
+     TRACKER_PICTURES_GRAPH, resource,
      "nco:creator", contact_resource);
   g_free (contact_resource);
 
@@ -755,7 +756,7 @@ account_miner_job_process_album (TrackerSparqlConnection *connection,
   gom_tracker_sparql_connection_insert_or_replace_triple
     (connection,
      cancellable, error,
-     datasource_urn, resource,
+     TRACKER_PICTURES_GRAPH, resource,
      "nie:contentCreated", date);
   g_free (date);
 
@@ -865,7 +866,7 @@ insert_shared_content_photos (TrackerSparqlConnection *connection,
   if (!gom_tracker_sparql_connection_insert_or_replace_triple (connection,
                                                                cancellable,
                                                                &local_error,
-                                                               datasource_urn,
+                                                               TRACKER_PICTURES_GRAPH,
                                                                source_urn,
                                                                "nie:relatedTo",
                                                                photo_resource_urn))
@@ -878,7 +879,7 @@ insert_shared_content_photos (TrackerSparqlConnection *connection,
   if (!gom_tracker_sparql_connection_insert_or_replace_triple (connection,
                                                                cancellable,
                                                                &local_error,
-                                                               datasource_urn,
+                                                               TRACKER_PICTURES_GRAPH,
                                                                photo_resource_urn,
                                                                "nie:links",
                                                                source_urn))
diff --git a/src/gom-media-server-miner.c b/src/gom-media-server-miner.c
index 490869e..32e08c6 100644
--- a/src/gom-media-server-miner.c
+++ b/src/gom-media-server-miner.c
@@ -65,14 +65,14 @@ account_miner_job_process_photo (GomAccountMinerJob *job,
     (connection,
      cancellable, error,
      &resource_exists,
-     datasource_urn, identifier,
+     TRACKER_PICTURES_GRAPH, identifier,
      "nfo:RemoteDataObject", class, NULL);
 
   if (*error != NULL)
     goto out;
 
   gom_tracker_update_datasource (connection, datasource_urn,
-                                 resource_exists, identifier, resource,
+                                 resource_exists, TRACKER_PICTURES_GRAPH, resource,
                                  cancellable, error);
   if (*error != NULL)
     goto out;
@@ -81,7 +81,7 @@ account_miner_job_process_photo (GomAccountMinerJob *job,
   gom_tracker_sparql_connection_insert_or_replace_triple
     (connection,
      cancellable, error,
-     datasource_urn, resource,
+     TRACKER_PICTURES_GRAPH, resource,
      "nie:url", photo->url);
 
   if (*error != NULL)
@@ -90,7 +90,7 @@ account_miner_job_process_photo (GomAccountMinerJob *job,
   gom_tracker_sparql_connection_insert_or_replace_triple
     (connection,
      cancellable, error,
-     datasource_urn, resource,
+     TRACKER_PICTURES_GRAPH, resource,
      "nie:mimeType", photo->mimetype);
 
   if (*error != NULL)
@@ -99,7 +99,7 @@ account_miner_job_process_photo (GomAccountMinerJob *job,
   gom_tracker_sparql_connection_insert_or_replace_triple
     (connection,
      cancellable, error,
-     datasource_urn, resource,
+     TRACKER_PICTURES_GRAPH, resource,
      "nie:title", photo->name);
 
   if (*error != NULL)
diff --git a/src/gom-miner.c b/src/gom-miner.c
index fafad90..49c8e58 100644
--- a/src/gom-miner.c
+++ b/src/gom-miner.c
@@ -368,7 +368,7 @@ gom_miner_ensure_datasource (GomMiner *self,
                           "  <%s> a nie:DataSource ; nao:identifier \"%s\" . "
                           "  <%s> a nie:InformationElement ; nie:rootElementOf <%s> ; nie:version \"%d\""
                           "}",
-                          datasource_urn,
+                          GOM_GRAPH,
                           datasource_urn, klass->miner_identifier,
                           root_element_urn, datasource_urn, klass->version);
 
@@ -393,8 +393,8 @@ gom_account_miner_job_query_existing (GomAccountMinerJob *job,
 
   select = g_string_new (NULL);
   g_string_append_printf (select,
-                          "SELECT ?urn nao:identifier(?urn) WHERE { ?urn nie:dataSource <%s> }",
-                          job->datasource_urn);
+                          "SELECT ?urn ?id WHERE { GRAPH <%s> { ?urn nie:dataSource <%s> ; nao:identifier 
?id . } }",
+                          GOM_GRAPH, job->datasource_urn);
 
   cursor = tracker_sparql_connection_query (job->connection,
                                             select->str,
@@ -407,9 +407,21 @@ gom_account_miner_job_query_existing (GomAccountMinerJob *job,
 
   while (tracker_sparql_cursor_next (cursor, cancellable, error))
     {
-      g_hash_table_insert (job->previous_resources,
-                           g_strdup (tracker_sparql_cursor_get_string (cursor, 1, NULL)),
-                           g_strdup (tracker_sparql_cursor_get_string (cursor, 0, NULL)));
+      const gchar *urn, *identifier;
+
+      urn = tracker_sparql_cursor_get_string (cursor, 0, NULL);
+      identifier = tracker_sparql_cursor_get_string (cursor, 1, NULL);
+
+      if (identifier != NULL)
+        {
+          g_hash_table_insert (job->previous_resources,
+                               g_strdup (identifier),
+                               g_strdup (urn));
+        }
+      else
+        {
+          g_warning ("Missing identifier for urn %s", urn);
+        }
     }
 
   g_object_unref (cursor);
@@ -481,16 +493,19 @@ gom_account_miner_job (GTask *task,
   if (error != NULL)
     goto out;
 
+  g_debug ("account miner: Querying existing accounts stored in database");
   gom_account_miner_job_query_existing (job, &error);
 
   if (error != NULL)
     goto out;
 
+  g_debug ("account miner: Querying remote server");
   gom_account_miner_job_query (job, &error);
 
   if (error != NULL)
     goto out;
 
+  g_debug ("account miner: Removing stale accounts");
   gom_account_miner_job_cleanup_previous (job, &error);
 
   if (error != NULL)
@@ -744,10 +759,15 @@ cleanup_job (gpointer data,
 
   /* find all our datasources in the tracker DB */
   select = g_string_new (NULL);
-  g_string_append_printf (select, "SELECT ?datasource nie:version(?root) WHERE { "
-                          "?datasource a nie:DataSource . "
-                          "?datasource nao:identifier \"%s\" . "
-                          "OPTIONAL { ?root nie:rootElementOf ?datasource } }",
+  g_string_append_printf (select,
+                          "SELECT ?datasource nie:version(?root) WHERE { "
+                          "  GRAPH <%s> { "
+                          "    ?datasource a nie:DataSource . "
+                          "    ?datasource nao:identifier \"%s\" . "
+                          "    OPTIONAL { ?root nie:rootElementOf ?datasource } "
+                          "  }"
+                          "}",
+                          GOM_GRAPH,
                           klass->miner_identifier);
 
   cursor = tracker_sparql_connection_query (self->priv->connection,
diff --git a/src/gom-miner.h b/src/gom-miner.h
index 5dcfc8d..8f83139 100644
--- a/src/gom-miner.h
+++ b/src/gom-miner.h
@@ -61,7 +61,6 @@ typedef struct _GomMinerPrivate GomMinerPrivate;
 typedef struct {
   GomMiner *miner;
   TrackerSparqlConnection *connection;
-  gchar *bus_name;
 
   GoaAccount *account;
   GHashTable *services;
diff --git a/src/gom-owncloud-miner.c b/src/gom-owncloud-miner.c
index 34d303b..623f2e1 100644
--- a/src/gom-owncloud-miner.c
+++ b/src/gom-owncloud-miner.c
@@ -100,14 +100,14 @@ account_miner_job_process_file (GomAccountMinerJob *job,
     (connection,
      cancellable, error,
      &resource_exists,
-     datasource_urn, identifier,
+     TRACKER_DOCUMENTS_GRAPH, identifier,
      "nfo:RemoteDataObject", class, NULL);
 
   if (*error != NULL)
     goto out;
 
   gom_tracker_update_datasource (connection, datasource_urn,
-                                 resource_exists, identifier, resource,
+                                 resource_exists, TRACKER_DOCUMENTS_GRAPH, resource,
                                  cancellable, error);
 
   if (*error != NULL)
@@ -117,7 +117,7 @@ account_miner_job_process_file (GomAccountMinerJob *job,
   modification_time = g_date_time_new_from_timeval_local (&tv);
   new_mtime = g_date_time_to_unix (modification_time);
   mtime_changed = gom_tracker_update_mtime (connection, new_mtime,
-                                            resource_exists, identifier, resource,
+                                            resource_exists, TRACKER_DOCUMENTS_GRAPH, resource,
                                             cancellable, error);
 
   if (*error != NULL)
@@ -133,7 +133,7 @@ account_miner_job_process_file (GomAccountMinerJob *job,
   gom_tracker_sparql_connection_insert_or_replace_triple
     (connection,
      cancellable, error,
-     datasource_urn, resource,
+     TRACKER_DOCUMENTS_GRAPH, resource,
      "nie:url", uri);
 
   if (*error != NULL)
@@ -156,7 +156,7 @@ account_miner_job_process_file (GomAccountMinerJob *job,
           parent_resource_urn = gom_tracker_sparql_connection_ensure_resource
             (connection, cancellable, error,
              NULL,
-             datasource_urn, parent_identifier,
+             GOM_GRAPH, parent_identifier,
              "nfo:RemoteDataObject", "nfo:DataContainer", NULL);
           g_checksum_reset (checksum);
           g_free (parent_identifier);
@@ -168,7 +168,7 @@ account_miner_job_process_file (GomAccountMinerJob *job,
           gom_tracker_sparql_connection_insert_or_replace_triple
             (connection,
              cancellable, error,
-             datasource_urn, resource,
+             TRACKER_DOCUMENTS_GRAPH, resource,
              "nie:isPartOf", parent_resource_urn);
           g_free (parent_resource_urn);
 
@@ -182,7 +182,7 @@ account_miner_job_process_file (GomAccountMinerJob *job,
           gom_tracker_sparql_connection_insert_or_replace_triple
             (connection,
              cancellable, error,
-             datasource_urn, resource,
+             TRACKER_DOCUMENTS_GRAPH, resource,
              "nie:mimeType", mime);
 
           if (*error != NULL)
@@ -194,7 +194,7 @@ account_miner_job_process_file (GomAccountMinerJob *job,
   gom_tracker_sparql_connection_insert_or_replace_triple
     (connection,
      cancellable, error,
-     datasource_urn, resource,
+     TRACKER_DOCUMENTS_GRAPH, resource,
      "nfo:fileName", display_name);
 
   if (*error != NULL)
@@ -416,6 +416,11 @@ query_owncloud (GomAccountMinerJob *job,
   mount = g_volume_get_mount (volume);
   if (mount == NULL)
     {
+      g_autofree gchar *volume_name;
+
+      volume_name = g_volume_get_name (volume);
+      g_debug ("Mounting Online Account volume %s", volume_name);
+
       data.error = error;
 
       context = g_main_context_new ();
@@ -436,6 +441,7 @@ query_owncloud (GomAccountMinerJob *job,
     }
 
   root = g_mount_get_root (mount);
+  g_debug ("Got volume from gnome-online-accounts: root is %s", g_file_peek_path (root));
   account_miner_job_traverse_dir (job, connection, previous_resources, datasource_urn, root, TRUE, 
cancellable, error);
 
   g_object_unref (root);
diff --git a/src/gom-tracker.c b/src/gom-tracker.c
index 63a4c29..0d1766c 100644
--- a/src/gom-tracker.c
+++ b/src/gom-tracker.c
@@ -26,16 +26,11 @@
 #include "gom-tracker.h"
 #include "gom-utils.h"
 
-static gchar *
-_tracker_utils_format_into_graph (const gchar *graph)
-{
-  return (graph != NULL) ? g_strdup_printf ("INTO <%s> ", graph) : g_strdup ("");
-}
-
 static gboolean
 gom_tracker_sparql_connection_get_string_attribute (TrackerSparqlConnection *connection,
                                                     GCancellable *cancellable,
                                                     GError **error,
+                                                    const gchar *graph,
                                                     const gchar *resource,
                                                     const gchar *attribute,
                                                     gchar **value)
@@ -45,8 +40,8 @@ gom_tracker_sparql_connection_get_string_attribute (TrackerSparqlConnection *con
   const gchar *string_value = NULL;
   gboolean res;
 
-  g_string_append_printf (select, "SELECT ?val { <%s> %s ?val }",
-                          resource, attribute);
+  g_string_append_printf (select, "SELECT ?val { GRAPH <%s> { <%s> %s ?val } }",
+                          graph, resource, attribute);
   cursor = tracker_sparql_connection_query (connection,
                                             select->str,
                                             cancellable, error);
@@ -86,7 +81,8 @@ gom_tracker_sparql_connection_ensure_resource (TrackerSparqlConnection *connecti
                                                const gchar *class,
                                                ...)
 {
-  GString *select, *insert, *inner;
+  GString *select, *inner;
+  gchar *insert;
   va_list args;
   const gchar *arg;
   TrackerSparqlCursor *cursor;
@@ -98,6 +94,8 @@ gom_tracker_sparql_connection_ensure_resource (TrackerSparqlConnection *connecti
   gchar *key = NULL, *val = NULL;
   gboolean exists = FALSE;
 
+  g_return_val_if_fail (graph != NULL, NULL);
+
   /* build the inner query with all the classes */
   va_start (args, class);
   inner = g_string_new (NULL);
@@ -112,7 +110,7 @@ gom_tracker_sparql_connection_ensure_resource (TrackerSparqlConnection *connecti
   /* query if such a resource is already in the DB */
   select = g_string_new (NULL);
   g_string_append_printf (select,
-                          "SELECT ?urn WHERE { ?urn %s }", inner->str);
+                          "SELECT ?urn WHERE { GRAPH <%s> { ?urn %s } }", graph, inner->str);
 
   cursor = tracker_sparql_connection_query (connection,
                                             select->str,
@@ -138,19 +136,12 @@ gom_tracker_sparql_connection_ensure_resource (TrackerSparqlConnection *connecti
     }
 
   /* not found, create the resource */
-  insert = g_string_new (NULL);
-  graph_str = _tracker_utils_format_into_graph (graph);
-
-  g_string_append_printf (insert, "INSERT %s { _:res %s }",
-                          graph_str, inner->str);
-  g_free (graph_str);
-  g_string_free (inner, TRUE);
-
+  insert = g_strdup_printf ("INSERT INTO <%s> { _:res %s }",
+                            graph, inner->str);
   insert_res =
-    tracker_sparql_connection_update_blank (connection, insert->str,
+    tracker_sparql_connection_update_blank (connection, insert,
                                             G_PRIORITY_DEFAULT, NULL, error);
-
-  g_string_free (insert, TRUE);
+  g_free (insert);
 
   if (*error != NULL)
     goto out;
@@ -194,10 +185,10 @@ gom_tracker_sparql_connection_insert_or_replace_triple (TrackerSparqlConnection
                                                         const gchar *property_value)
 {
   GString *insert;
-  gchar *graph_str, *quoted;
+  gchar *quoted;
   gboolean retval = TRUE;
 
-  graph_str = _tracker_utils_format_into_graph (graph);
+  g_return_val_if_fail (graph != NULL, FALSE);
 
   /* the "null" value must not be quoted */
   if (property_value == NULL)
@@ -208,8 +199,8 @@ gom_tracker_sparql_connection_insert_or_replace_triple (TrackerSparqlConnection
   insert = g_string_new (NULL);
   g_string_append_printf
     (insert,
-     "INSERT OR REPLACE %s { <%s> a nie:InformationElement, nie:DataObject ; %s %s }",
-     graph_str, resource, property_name, quoted);
+     "INSERT OR REPLACE INTO <%s> { <%s> a nie:InformationElement, nie:DataObject ; %s %s }",
+     graph, resource, property_name, quoted);
   g_free (quoted);
 
   g_debug ("Insert or replace triple: query %s", insert->str);
@@ -223,8 +214,6 @@ gom_tracker_sparql_connection_insert_or_replace_triple (TrackerSparqlConnection
   if (*error != NULL)
     retval = FALSE;
 
-  g_free (graph_str);
-
   return retval;
 }
 
@@ -271,6 +260,7 @@ gboolean
 gom_tracker_sparql_connection_toggle_favorite (TrackerSparqlConnection *connection,
                                                GCancellable *cancellable,
                                                GError **error,
+                                               const gchar *graph,
                                                const gchar *resource,
                                                gboolean favorite)
 {
@@ -279,15 +269,15 @@ gom_tracker_sparql_connection_toggle_favorite (TrackerSparqlConnection *connecti
   gboolean retval = TRUE;
 
   if (favorite)
-    op_str = "INSERT OR REPLACE";
+    op_str = "INSERT OR REPLACE INTO";
   else
-    op_str = "DELETE";
+    op_str = "DELETE FROM";
 
   update = g_string_new (NULL);
   g_string_append_printf
     (update,
-     "%s { <%s> nao:hasTag nao:predefined-tag-favorite }",
-     op_str, resource);
+     "%s <%s> { <%s> nao:hasTag nao:predefined-tag-favorite }",
+     op_str, graph, resource);
 
   g_debug ("Toggle favorite: query %s", update->str);
 
@@ -321,9 +311,13 @@ gom_tracker_utils_ensure_contact_resource (TrackerSparqlConnection *connection,
   mail_uri = g_strconcat ("mailto:";, email, NULL);
   select = g_string_new (NULL);
   g_string_append_printf (select,
-                          "SELECT ?urn WHERE { ?urn a nco:Contact . "
-                          "?urn nco:hasEmailAddress ?mail . "
-                          "FILTER (fn:contains(?mail, \"%s\" )) }", mail_uri);
+                          "SELECT ?urn WHERE { "
+                          "  GRAPH <%s> { "
+                          "    ?urn a nco:Contact . "
+                          "    ?urn nco:hasEmailAddress ?mail . "
+                          "    FILTER (fn:contains(?mail, \"%s\" )) "
+                          "  }"
+                          "}", TRACKER_CONTACTS_GRAPH, mail_uri);
 
   cursor = tracker_sparql_connection_query (connection,
                                             select->str,
@@ -351,8 +345,9 @@ gom_tracker_utils_ensure_contact_resource (TrackerSparqlConnection *connection,
   insert = g_string_new (NULL);
 
   g_string_append_printf (insert,
-                          "INSERT { <%s> a nco:EmailAddress ; nco:emailAddress \"%s\" . "
+                          "INSERT INTO <%s> { <%s> a nco:EmailAddress ; nco:emailAddress \"%s\" . "
                           "_:res a nco:Contact ; nco:hasEmailAddress <%s> ; nco:fullname \"%s\" . }",
+                          TRACKER_CONTACTS_GRAPH,
                           mail_uri, email,
                           mail_uri, fullname);
 
@@ -397,6 +392,7 @@ gchar *
 gom_tracker_utils_ensure_equipment_resource (TrackerSparqlConnection *connection,
                                              GCancellable *cancellable,
                                              GError **error,
+                                             const gchar *graph,
                                              const gchar *make,
                                              const gchar *model)
 {
@@ -416,7 +412,7 @@ gom_tracker_utils_ensure_equipment_resource (TrackerSparqlConnection *connection
   equip_uri = tracker_sparql_escape_uri_printf ("urn:equipment:%s:%s:",
                                                 make != NULL ? make : "",
                                                 model != NULL ? model : "");
-  select = g_strdup_printf ("SELECT <%s> WHERE { }", equip_uri);
+  select = g_strdup_printf ("ASK { GRAPH <%s> { <%s> a nfo:Equipment } }", graph, equip_uri);
 
   local_error = NULL;
   cursor = tracker_sparql_connection_query (connection, select, cancellable, &local_error);
@@ -436,20 +432,19 @@ gom_tracker_utils_ensure_equipment_resource (TrackerSparqlConnection *connection
 
   if (res)
     {
-      const gchar *cursor_uri;
-
-      cursor_uri = tracker_sparql_cursor_get_string (cursor, 0, NULL);
-      if (g_strcmp0 (cursor_uri, equip_uri) == 0)
+      if (tracker_sparql_cursor_get_boolean (cursor, 0))
         {
-          /* return the found resource */
-          retval = g_strdup (cursor_uri);
+          /* The resource exists */
+          retval = equip_uri;
+          equip_uri = NULL;
           g_debug ("Found resource in the store: %s", retval);
           goto out;
         }
     }
 
   /* not found, create the resource */
-  insert = g_strdup_printf ("INSERT { <%s> a nfo:Equipment ; nfo:manufacturer \"%s\" ; nfo:model \"%s\" }",
+  insert = g_strdup_printf ("INSERT INTO <%s> { <%s> a nfo:Equipment ; nfo:manufacturer \"%s\" ; nfo:model 
\"%s\" }",
+                            graph,
                             equip_uri,
                             make,
                             model);
@@ -480,7 +475,7 @@ void
 gom_tracker_update_datasource (TrackerSparqlConnection  *connection,
                                const gchar              *datasource_urn,
                                gboolean                  resource_exists,
-                               const gchar              *identifier,
+                               const gchar              *graph,
                                const gchar              *resource,
                                GCancellable             *cancellable,
                                GError                  **error)
@@ -498,7 +493,7 @@ gom_tracker_update_datasource (TrackerSparqlConnection  *connection,
 
       res = gom_tracker_sparql_connection_get_string_attribute
         (connection, cancellable, error,
-         resource, "nie:dataSource", &old_value);
+         graph, resource, "nie:dataSource", &old_value);
       g_clear_error (error);
 
       if (res)
@@ -514,7 +509,7 @@ gom_tracker_update_datasource (TrackerSparqlConnection  *connection,
   if (set_datasource)
     gom_tracker_sparql_connection_set_triple
       (connection, cancellable, error,
-       identifier, resource,
+       graph, resource,
        "nie:dataSource", datasource_urn);
 }
 
@@ -522,7 +517,7 @@ gboolean
 gom_tracker_update_mtime (TrackerSparqlConnection  *connection,
                           gint64                    new_mtime,
                           gboolean                  resource_exists,
-                          const gchar              *identifier,
+                          const gchar              *graph,
                           const gchar              *resource,
                           GCancellable             *cancellable,
                           GError                  **error)
@@ -536,7 +531,7 @@ gom_tracker_update_mtime (TrackerSparqlConnection  *connection,
     {
       res = gom_tracker_sparql_connection_get_string_attribute
         (connection, cancellable, error,
-         resource, "nie:contentLastModified", &old_value);
+         graph, resource, "nie:contentLastModified", &old_value);
       g_clear_error (error);
 
       if (res)
@@ -552,7 +547,7 @@ gom_tracker_update_mtime (TrackerSparqlConnection  *connection,
   date = gom_iso8601_from_timestamp (new_mtime);
   gom_tracker_sparql_connection_insert_or_replace_triple
     (connection, cancellable, error,
-     identifier, resource,
+     graph, resource,
      "nie:contentLastModified", date);
   g_free (date);
 
diff --git a/src/gom-tracker.h b/src/gom-tracker.h
index 94a39e8..a5ae6fd 100644
--- a/src/gom-tracker.h
+++ b/src/gom-tracker.h
@@ -29,6 +29,14 @@
 
 G_BEGIN_DECLS
 
+/* The graph where we store account meta information */
+#define GOM_GRAPH "tracker.api.gnome.org/ontology/v3/gnome-online-miners"
+
+/* Graphs where we store content information */
+#define TRACKER_CONTACTS_GRAPH "http://tracker.api.gnome.org/ontology/v3/tracker#Contacts";
+#define TRACKER_DOCUMENTS_GRAPH "http://tracker.api.gnome.org/ontology/v3/tracker#Documents";
+#define TRACKER_PICTURES_GRAPH "http://tracker.api.gnome.org/ontology/v3/tracker#Pictures";
+
 gchar *gom_tracker_sparql_connection_ensure_resource (TrackerSparqlConnection *connection,
                                                       GCancellable *cancellable,
                                                       GError **error,
@@ -57,6 +65,7 @@ gboolean gom_tracker_sparql_connection_set_triple (TrackerSparqlConnection *conn
 gboolean gom_tracker_sparql_connection_toggle_favorite (TrackerSparqlConnection *connection,
                                                         GCancellable *cancellable,
                                                         GError **error,
+                                                        const gchar *graph,
                                                         const gchar *resource,
                                                         gboolean favorite);
 
@@ -69,20 +78,21 @@ gchar* gom_tracker_utils_ensure_contact_resource (TrackerSparqlConnection *conne
 gchar *gom_tracker_utils_ensure_equipment_resource (TrackerSparqlConnection *connection,
                                                     GCancellable *cancellable,
                                                     GError **error,
+                                                    const gchar *graph,
                                                     const gchar *make,
                                                     const gchar *model);
 
 void gom_tracker_update_datasource (TrackerSparqlConnection  *connection,
                                     const gchar              *datasource_urn,
                                     gboolean                  resource_exists,
-                                    const gchar              *identifier,
+                                    const gchar              *graph,
                                     const gchar              *resource,
                                     GCancellable             *cancellable,
                                     GError                  **error);
 gboolean gom_tracker_update_mtime (TrackerSparqlConnection  *connection,
                                    gint64                    new_mtime,
                                    gboolean                  resource_exists,
-                                   const gchar              *identifier,
+                                   const gchar              *graph,
                                    const gchar              *resource,
                                    GCancellable             *cancellable,
                                    GError                  **error);
diff --git a/src/gom-zpj-miner.c b/src/gom-zpj-miner.c
index 6dff947..1372de5 100644
--- a/src/gom-zpj-miner.c
+++ b/src/gom-zpj-miner.c
@@ -70,14 +70,14 @@ account_miner_job_process_entry (GomAccountMinerJob *job,
     (connection,
      cancellable, error,
      &resource_exists,
-     datasource_urn, identifier,
+     TRACKER_PICTURES_GRAPH, identifier,
      "nfo:RemoteDataObject", class, NULL);
 
   if (*error != NULL)
     goto out;
 
   gom_tracker_update_datasource (connection, datasource_urn,
-                                 resource_exists, identifier, resource,
+                                 resource_exists, TRACKER_PICTURES_GRAPH, resource,
                                  cancellable, error);
 
   if (*error != NULL)
@@ -86,7 +86,7 @@ account_miner_job_process_entry (GomAccountMinerJob *job,
   updated_time = zpj_skydrive_entry_get_updated_time (entry);
   new_mtime = g_date_time_to_unix (updated_time);
   mtime_changed = gom_tracker_update_mtime (connection, new_mtime,
-                                            resource_exists, identifier, resource,
+                                            resource_exists, TRACKER_PICTURES_GRAPH, resource,
                                             cancellable, error);
 
   if (*error != NULL)
@@ -102,7 +102,7 @@ account_miner_job_process_entry (GomAccountMinerJob *job,
   gom_tracker_sparql_connection_insert_or_replace_triple
     (connection,
      cancellable, error,
-     datasource_urn, resource,
+     TRACKER_PICTURES_GRAPH, resource,
      "nie:url", identifier);
 
   if (*error != NULL)
@@ -119,7 +119,7 @@ account_miner_job_process_entry (GomAccountMinerJob *job,
       parent_resource_urn = gom_tracker_sparql_connection_ensure_resource
         (connection, cancellable, error,
          NULL,
-         datasource_urn, parent_identifier,
+         TRACKER_PICTURES_GRAPH, parent_identifier,
          "nfo:RemoteDataObject", "nfo:DataContainer", NULL);
       g_free (parent_identifier);
 
@@ -129,7 +129,7 @@ account_miner_job_process_entry (GomAccountMinerJob *job,
       gom_tracker_sparql_connection_insert_or_replace_triple
         (connection,
          cancellable, error,
-         datasource_urn, resource,
+         TRACKER_PICTURES_GRAPH, resource,
          "nie:isPartOf", parent_resource_urn);
       g_free (parent_resource_urn);
 
@@ -142,7 +142,7 @@ account_miner_job_process_entry (GomAccountMinerJob *job,
           gom_tracker_sparql_connection_insert_or_replace_triple
             (connection,
              cancellable, error,
-             datasource_urn, resource,
+             TRACKER_PICTURES_GRAPH, resource,
              "nie:mimeType", mime);
           g_free (mime);
 
@@ -154,7 +154,7 @@ account_miner_job_process_entry (GomAccountMinerJob *job,
   gom_tracker_sparql_connection_insert_or_replace_triple
     (connection,
      cancellable, error,
-     datasource_urn, resource,
+     TRACKER_PICTURES_GRAPH, resource,
      "nie:description", zpj_skydrive_entry_get_description (entry));
 
   if (*error != NULL)
@@ -163,7 +163,7 @@ account_miner_job_process_entry (GomAccountMinerJob *job,
   gom_tracker_sparql_connection_insert_or_replace_triple
     (connection,
      cancellable, error,
-     datasource_urn, resource,
+     TRACKER_PICTURES_GRAPH, resource,
      "nfo:fileName", name);
 
   if (*error != NULL)
@@ -180,7 +180,7 @@ account_miner_job_process_entry (GomAccountMinerJob *job,
   gom_tracker_sparql_connection_insert_or_replace_triple
     (connection,
      cancellable, error,
-     datasource_urn, resource,
+     TRACKER_PICTURES_GRAPH, resource,
      "nco:creator", contact_resource);
   g_free (contact_resource);
 
@@ -192,7 +192,7 @@ account_miner_job_process_entry (GomAccountMinerJob *job,
   gom_tracker_sparql_connection_insert_or_replace_triple
     (connection,
      cancellable, error,
-     datasource_urn, resource,
+     TRACKER_PICTURES_GRAPH, resource,
      "nie:contentCreated", date);
   g_free (date);
 


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