[gnome-documents/wip/skydrive: 8/24] miner: create a graph for each Windows Live account



commit b2f9863df0adb7af26cc3c5d408f562039874e61
Author: Debarshi Ray <debarshir gnome org>
Date:   Thu May 24 22:30:48 2012 +0200

    miner: create a graph for each Windows Live account
    
    The nie:DataSource, the files and folders are all a part of this
    graph. The URN of the graph is gd:goa-account:<account_ID>, which is
    the same as the nie:DataSource representing the account.
    
    Therefore, when an account has been removed we can just delete the
    whole graph.
    
    Fixes: https://bugzilla.gnome.org/666535

 src/miner/gd-zpj-miner.c |   52 +++++++++++++++++++++++++++++++---------------
 1 files changed, 35 insertions(+), 17 deletions(-)
---
diff --git a/src/miner/gd-zpj-miner.c b/src/miner/gd-zpj-miner.c
index 805201f..a5e7474 100644
--- a/src/miner/gd-zpj-miner.c
+++ b/src/miner/gd-zpj-miner.c
@@ -157,11 +157,12 @@ account_miner_job_cleanup_previous (AccountMinerJob *job,
 static gboolean
 account_miner_job_process_entry (AccountMinerJob *job,
                                  ZpjSkydriveEntry *entry,
+                                 const gchar *datasource_urn,
                                  GError **error)
 {
   GDateTime *created_time, *updated_time;
   gchar *resource = NULL;
-  gchar *date, *datasource_urn, *identifier;
+  gchar *date, *identifier;
   const gchar *class = NULL, *id;
 
   id = zpj_skydrive_entry_get_id (entry);
@@ -181,21 +182,17 @@ account_miner_job_process_entry (AccountMinerJob *job,
   resource = gd_miner_tracker_sparql_connection_ensure_resource
     (job->connection,
      job->cancellable, error,
-     identifier, identifier,
+     datasource_urn, identifier,
      "nfo:RemoteDataObject", class, NULL);
 
   if (*error != NULL)
     goto out;
 
-  datasource_urn = g_strdup_printf ("gd:goa-account:%s",
-                                    goa_account_get_id (job->account));
   gd_miner_tracker_sparql_connection_set_triple
      (job->connection, job->cancellable, error,
-      identifier, resource,
+      datasource_urn, resource,
       "nie:dataSource", datasource_urn);
 
-  g_free (datasource_urn);
-
   if (ZPJ_IS_SKYDRIVE_FILE (entry))
     {
       gchar *parent_resource_urn, *parent_identifier;
@@ -205,7 +202,7 @@ account_miner_job_process_entry (AccountMinerJob *job,
       parent_identifier = g_strconcat ("gd:collection:windows-live:skydrive:", parent_id, NULL);
       parent_resource_urn = gd_miner_tracker_sparql_connection_ensure_resource
         (job->connection, job->cancellable, error,
-         NULL, parent_identifier,
+         datasource_urn, parent_identifier,
          "nfo:RemoteDataObject", "nfo:DataContainer", NULL);
       g_free (parent_identifier);
 
@@ -215,7 +212,7 @@ account_miner_job_process_entry (AccountMinerJob *job,
       gd_miner_tracker_sparql_connection_insert_or_replace_triple
         (job->connection,
          job->cancellable, error,
-         identifier, resource,
+         datasource_urn, resource,
          "nie:isPartOf", parent_resource_urn);
       g_free (parent_resource_urn);
 
@@ -226,7 +223,7 @@ account_miner_job_process_entry (AccountMinerJob *job,
   gd_miner_tracker_sparql_connection_insert_or_replace_triple
     (job->connection,
      job->cancellable, error,
-     identifier, resource,
+     datasource_urn, resource,
      "nie:description", zpj_skydrive_entry_get_description (entry));
 
   if (*error != NULL)
@@ -237,7 +234,7 @@ account_miner_job_process_entry (AccountMinerJob *job,
   gd_miner_tracker_sparql_connection_insert_or_replace_triple
     (job->connection,
      job->cancellable, error,
-     identifier, resource,
+     datasource_urn, resource,
      "nie:contentCreated", date);
   g_free (date);
 
@@ -249,7 +246,7 @@ account_miner_job_process_entry (AccountMinerJob *job,
   gd_miner_tracker_sparql_connection_insert_or_replace_triple
     (job->connection,
      job->cancellable, error,
-     identifier, resource,
+     datasource_urn, resource,
      "nie:contentLastModified", date);
   g_free (date);
 
@@ -269,6 +266,7 @@ account_miner_job_process_entry (AccountMinerJob *job,
 static void
 account_miner_job_traverse_folder (AccountMinerJob *job,
                                    const gchar *folder_id,
+                                   const gchar *datasource_urn,
                                    GError **error)
 {
   GList *entries, *l;
@@ -288,11 +286,11 @@ account_miner_job_traverse_folder (AccountMinerJob *job,
       id = zpj_skydrive_entry_get_id (entry);
 
       if (ZPJ_IS_SKYDRIVE_FOLDER (entry))
-        account_miner_job_traverse_folder (job, id, error);
+        account_miner_job_traverse_folder (job, id, datasource_urn, error);
       else if (ZPJ_IS_SKYDRIVE_PHOTO (entry))
         continue;
 
-      account_miner_job_process_entry (job, entry, error);
+      account_miner_job_process_entry (job, entry, datasource_urn, error);
 
       if (*error != NULL)
         {
@@ -308,7 +306,18 @@ static void
 account_miner_job_query_zpj (AccountMinerJob *job,
                              GError **error)
 {
-  account_miner_job_traverse_folder (job, ZPJ_SKYDRIVE_FOLDER_SKYDRIVE, error);
+  gchar *datasource_urn = NULL;
+
+  datasource_urn = g_strconcat ("gd:goa-account:",
+                                goa_account_get_id (job->account),
+                                NULL);
+
+  account_miner_job_traverse_folder (job,
+                                     ZPJ_SKYDRIVE_FOLDER_SKYDRIVE,
+                                     datasource_urn,
+                                     error);
+
+  g_free (datasource_urn);
 }
 
 
@@ -348,11 +357,20 @@ account_miner_job_ensure_datasource (AccountMinerJob *job,
                                      GError **error)
 {
   GString *datasource_insert;
+  gchar *datasource_urn;
 
   datasource_insert = g_string_new (NULL);
+  datasource_urn = g_strconcat ("gd:goa-account:",
+                                goa_account_get_id (job->account),
+                                NULL);
   g_string_append_printf (datasource_insert,
-                          "INSERT OR REPLACE { <gd:goa-account:%s> a nie:DataSource ; nao:identifier \"%s\" }",
-                          goa_account_get_id (job->account), MINER_IDENTIFIER);
+                          "INSERT OR REPLACE INTO <%s> {"
+                          "  <%s> a nie:DataSource ; nao:identifier \"%s\""
+                          "}",
+                          datasource_urn,
+                          datasource_urn,
+                          MINER_IDENTIFIER);
+  g_free (datasource_urn);
 
   tracker_sparql_connection_update (job->connection,
                                     datasource_insert->str,



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