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



commit 7ef6a102f9b433fa381d1692945c49669b30ade9
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 3fe696c..59cfea1 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);
@@ -179,21 +180,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;
@@ -203,7 +200,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);
 
@@ -213,7 +210,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);
 
@@ -224,7 +221,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)
@@ -235,7 +232,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);
 
@@ -247,7 +244,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);
 
@@ -267,6 +264,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;
@@ -286,11 +284,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)
         {
@@ -306,7 +304,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);
 }
 
 
@@ -346,11 +355,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]