[tracker/writeback] All miner SPARQL Update queries need FROM or INTO to avoid writeback



commit 8a20783b7ef66b553a9201c6cdcb9473bf3ea0cd
Author: Philip Van Hoof <philip codeminded be>
Date:   Thu Nov 12 11:55:16 2009 +0100

    All miner SPARQL Update queries need FROM or INTO to avoid writeback
    
    When INTO or FROM are passed, graph in tracker_writeback_check wont be NULL.
    A NULL graph means 'default graph' or 'something that came from the user'.
    We only want to do writeback for things that came from the user. This is how
    we distinguish between content from the miner and content from the user.

 src/libtracker-common/tracker-sparql-builder.vala |    7 +++-
 src/libtracker-data/tracker-data-update.c         |   38 +++++++++++---------
 src/libtracker-miner/tracker-miner-fs.c           |   14 ++++----
 src/plugins/evolution/tracker-evolution-plugin.c  |   21 +++++++----
 src/plugins/kmail/tracker-kmail-registrar.c       |    9 +++--
 src/tracker-extract/tracker-extract.c             |    2 +-
 src/tracker-miner-fs/tracker-miner-applications.c |    8 ++---
 src/tracker-miner-fs/tracker-miner-files.c        |   39 +++++++++++----------
 8 files changed, 76 insertions(+), 62 deletions(-)
---
diff --git a/src/libtracker-common/tracker-sparql-builder.vala b/src/libtracker-common/tracker-sparql-builder.vala
index 09ef643..00bf7c7 100644
--- a/src/libtracker-common/tracker-sparql-builder.vala
+++ b/src/libtracker-common/tracker-sparql-builder.vala
@@ -51,11 +51,14 @@ public class Tracker.SparqlBuilder : Object {
 		str.append ("DROP GRAPH <%s>\n".printf (iri));
 	}
 
-	public void insert_open ()
+	public void insert_open (string? iri)
 		requires (state == State.UPDATE)
 	{
 		states += State.INSERT;
-		str.append ("INSERT {\n");
+		if (iri != null)
+			str.append ("INSERT INTO <%s> {\n".printf (iri));
+		else
+			str.append ("INSERT {\n");
 	}
 
 	public void insert_close ()
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index ca6f5c7..bb4f472 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -1525,10 +1525,10 @@ tracker_data_update_enable_volume (const gchar *udi,
 	mount_path_file = g_file_new_for_path (mount_path);
 	mount_path_uri = g_file_get_uri (mount_path_file);
 
-	delete_q = g_strdup_printf ("DELETE { <%s> tracker:mountPoint ?d } WHERE { <%s> tracker:mountPoint ?d }", 
-				    removable_device_urn, removable_device_urn);
-	set_q = g_strdup_printf ("INSERT { <%s> a tracker:Volume; tracker:mountPoint <%s> }", 
-				 removable_device_urn, mount_path_uri);
+	delete_q = g_strdup_printf ("DELETE FROM <%s> { <%s> tracker:mountPoint ?d } WHERE { <%s> tracker:mountPoint ?d }", 
+	                            removable_device_urn, removable_device_urn, removable_device_urn);
+	set_q = g_strdup_printf ("INSERT INTO <%s> { <%s> a tracker:Volume; tracker:mountPoint <%s> }", 
+	                         removable_device_urn, removable_device_urn, mount_path_uri);
 
 	tracker_data_update_sparql (delete_q, &error);
 
@@ -1548,10 +1548,10 @@ tracker_data_update_enable_volume (const gchar *udi,
 	g_free (set_q);
 	g_free (delete_q);
 
-	delete_q = g_strdup_printf ("DELETE { <%s> tracker:isMounted ?d } WHERE { <%s> tracker:isMounted ?d }", 
-				    removable_device_urn, removable_device_urn);
-	set_q = g_strdup_printf ("INSERT { <%s> a tracker:Volume; tracker:isMounted true }", 
-				 removable_device_urn);
+	delete_q = g_strdup_printf ("DELETE FROM <%s> { <%s> tracker:isMounted ?d } WHERE { <%s> tracker:isMounted ?d }", 
+	                            removable_device_urn, removable_device_urn, removable_device_urn);
+	set_q = g_strdup_printf ("INSERT INTO <%s> { <%s> a tracker:Volume; tracker:isMounted true }", 
+	                         removable_device_urn, removable_device_urn);
 
 	tracker_data_update_sparql (delete_q, &error);
 
@@ -1587,9 +1587,10 @@ tracker_data_update_reset_volume (const gchar *uri)
 
 	mnow = time (NULL);
 	now_as_string = tracker_date_to_string (mnow);
-	delete_q = g_strdup_printf ("DELETE { <%s> tracker:unmountDate ?d } WHERE { <%s> tracker:unmountDate ?d }", uri, uri);
-	set_q = g_strdup_printf ("INSERT { <%s> a tracker:Volume; tracker:unmountDate \"%s\" }", 
-				 uri, now_as_string);
+	delete_q = g_strdup_printf ("DELETE FROM <%s> { <%s> tracker:unmountDate ?d } WHERE { <%s> tracker:unmountDate ?d }", 
+	                            uri, uri, uri);
+	set_q = g_strdup_printf ("INSERT INTO <%s> { <%s> a tracker:Volume; tracker:unmountDate \"%s\" }", 
+	                         uri, uri, now_as_string);
 
 	tracker_data_update_sparql (delete_q, &error);
 
@@ -1627,10 +1628,10 @@ tracker_data_update_disable_volume (const gchar *udi)
 
 	tracker_data_update_reset_volume (removable_device_urn);
 
-	delete_q = g_strdup_printf ("DELETE { <%s> tracker:isMounted ?d } WHERE { <%s> tracker:isMounted ?d }", 
-				    removable_device_urn, removable_device_urn);
-	set_q = g_strdup_printf ("INSERT { <%s> a tracker:Volume; tracker:isMounted false }", 
-				 removable_device_urn);
+	delete_q = g_strdup_printf ("DELETE FROM <%s> { <%s> tracker:isMounted ?d } WHERE { <%s> tracker:isMounted ?d }", 
+	                            removable_device_urn, removable_device_urn, removable_device_urn);
+	set_q = g_strdup_printf ("INSERT INTO <%s> { <%s> a tracker:Volume; tracker:isMounted false }", 
+	                         removable_device_urn, removable_device_urn);
 
 	tracker_data_update_sparql (delete_q, &error);
 
@@ -1675,8 +1676,11 @@ tracker_data_update_disable_all_volumes (void)
 	tracker_db_statement_execute (stmt, NULL);
 	g_object_unref (stmt);
 
-	delete_q = g_strdup_printf ("DELETE { ?o tracker:isMounted ?d } WHERE { ?o tracker:isMounted ?d  FILTER (?o != <"TRACKER_NON_REMOVABLE_MEDIA_DATASOURCE_URN"> ) }");
-	set_q = g_strdup_printf ("INSERT { ?o a tracker:Volume; tracker:isMounted false } WHERE { ?o a tracker:Volume FILTER (?o != <"TRACKER_NON_REMOVABLE_MEDIA_DATASOURCE_URN"> ) }");
+	/* The INTO and FROM uris are not really right, but it should be harmless:
+	 * we just want graph to be != NULL in tracker-store/tracker-writeback.c */
+
+	delete_q = g_strdup_printf ("DELETE FROM <"TRACKER_NON_REMOVABLE_MEDIA_DATASOURCE_URN"> { ?o tracker:isMounted ?d } WHERE { ?o tracker:isMounted ?d  FILTER (?o != <"TRACKER_NON_REMOVABLE_MEDIA_DATASOURCE_URN"> ) }");
+	set_q = g_strdup_printf ("INSERT INTO <"TRACKER_NON_REMOVABLE_MEDIA_DATASOURCE_URN"> { ?o a tracker:Volume; tracker:isMounted false } WHERE { ?o a tracker:Volume FILTER (?o != <"TRACKER_NON_REMOVABLE_MEDIA_DATASOURCE_URN"> ) }");
 
 	tracker_data_update_sparql (delete_q, &error);
 
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index 7d7ef67..485ea3a 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -982,14 +982,14 @@ item_remove (TrackerMinerFS *fs,
 
 	/* Delete all children */
 	g_string_append_printf (sparql,
-				"DELETE { ?u a rdfs:Resource } "
+				"DELETE FROM <%s> { ?u a rdfs:Resource } "
 				"WHERE { ?u nfo:belongsToContainer ?p . FILTER (fn:starts-with (?p, \"%s\")) } ",
-				slash_uri);
+				uri, slash_uri);
 
 	/* Delete resource itself */
 	g_string_append_printf (sparql,
-				"DELETE { <%s> a rdfs:Resource }",
-				uri);
+				"DELETE FROM <%s> { <%s> a rdfs:Resource }",
+				uri, uri);
 
 	data = process_data_new (file, NULL, NULL);
 	fs->private->processing_pool = g_list_prepend (fs->private->processing_pool, data);
@@ -1121,10 +1121,10 @@ item_move (TrackerMinerFS *fs,
 	sparql = g_string_new ("");
 
 	g_string_append_printf (sparql,
-				"DELETE { <%s> nfo:fileName ?o } WHERE { <%s> nfo:fileName ?o }",
-				source_uri, source_uri);
+				"DELETE FROM <%s> { <%s> nfo:fileName ?o } WHERE { <%s> nfo:fileName ?o }",
+				source_uri, source_uri, source_uri);
 
-	g_string_append (sparql, " INSERT {");
+	g_string_append_printf (sparql, " INSERT INTO <%s> {", uri);
 
 	escaped_filename = g_strescape (g_file_info_get_display_name (file_info), NULL);
 
diff --git a/src/plugins/evolution/tracker-evolution-plugin.c b/src/plugins/evolution/tracker-evolution-plugin.c
index eb39a8d..2e872ad 100644
--- a/src/plugins/evolution/tracker-evolution-plugin.c
+++ b/src/plugins/evolution/tracker-evolution-plugin.c
@@ -340,9 +340,9 @@ send_sparql_commit (TrackerEvolutionPlugin *self, gboolean update)
 	if (priv->client) {
 		if (update) {
 			gchar *date_s = tracker_date_to_string (time (NULL));
-			gchar *update = g_strdup_printf ("DELETE { <" DATASOURCE_URN "> nie:contentLastModified ?d } "
+			gchar *update = g_strdup_printf ("DELETE FROM <"DATASOURCE_URN"> { <" DATASOURCE_URN "> nie:contentLastModified ?d } "
 			                                 "WHERE { <" DATASOURCE_URN "> a nie:InformationElement ; nie:contentLastModified ?d } \n"
-			                                 "INSERT { <" DATASOURCE_URN "> nie:contentLastModified \"%s\" }",
+			                                 "INSERT INTO <"DATASOURCE_URN"> { <" DATASOURCE_URN "> nie:contentLastModified \"%s\" }",
 			                                 date_s);
 
 			send_sparql_update (self, update);
@@ -652,7 +652,7 @@ on_folder_summary_changed (CamelFolder *folder,
 
 			tracker_sparql_builder_drop_graph (sparql, uri);
 
-			tracker_sparql_builder_insert_open (sparql);
+			tracker_sparql_builder_insert_open (sparql, uri);
 
 			process_fields (sparql, uid, flags, sent, subject, 
 			                from, to, cc, size, folder, uri);
@@ -717,7 +717,11 @@ on_folder_summary_changed (CamelFolder *folder,
 	/* the uid_removed member contains the removed-from-the-summary items */
 
 	if (changes->uid_removed && changes->uid_removed->len > 0) {
-		GString *sparql = g_string_new ("DELETE { \n");
+
+		/* The FROM uri is not exactly right here, but we just want 
+		 * graph != NULL in tracker-store/tracker-writeback.c */
+
+		GString *sparql = g_string_new ("DELETE FROM <"DATASOURCE_URN"> { \n");
 
 		for (i = 0; i< changes->uid_removed->len; i++) {
 
@@ -954,7 +958,7 @@ introduce_walk_folders_in_folder (TrackerEvolutionPlugin *self,
 
 					tracker_sparql_builder_drop_graph (sparql, uri);
 
-					tracker_sparql_builder_insert_open (sparql);
+					tracker_sparql_builder_insert_open (sparql, uri);
 
 					process_fields (sparql, uid, flags, sent, 
 					                subject, from, to, cc, size, 
@@ -1191,7 +1195,10 @@ introduce_store_deal_with_deleted (TrackerEvolutionPlugin *self,
 		}
 
 		if (count > 0) {
-			GString *sparql = g_string_new ("DELETE { \n");
+			/* The FROM uri is not exactly right here, but we just want 
+			 * graph != NULL in tracker-store/tracker-writeback.c */
+
+			GString *sparql = g_string_new ("DELETE FROM <"DATASOURCE_URN"> { \n");
 
 			for (i = 0; i < subjects_a->len; i++) {
 				g_string_append_printf (sparql, "\t<%s> a rdfs:Resource . \n", 
@@ -1656,7 +1663,7 @@ register_client_second_half (ClientRegistry *info)
 
 	if (info->last_checkout < too_old) {
 
-		send_sparql_update (info->self, "DELETE { ?s a rdfs:Resource } "
+		send_sparql_update (info->self, "DELETE FROM <"DATASOURCE_URN"> { ?s a rdfs:Resource } "
 		                                "WHERE { ?s nie:dataSource <" DATASOURCE_URN "> }");
 		send_sparql_commit (info->self, FALSE);
 
diff --git a/src/plugins/kmail/tracker-kmail-registrar.c b/src/plugins/kmail/tracker-kmail-registrar.c
index cf1afba..b7c478f 100644
--- a/src/plugins/kmail/tracker-kmail-registrar.c
+++ b/src/plugins/kmail/tracker-kmail-registrar.c
@@ -166,7 +166,7 @@ perform_set (TrackerKMailRegistrar *object,
 
 	sparql = tracker_sparql_builder_new_update ();
 
-	tracker_sparql_builder_insert_open (sparql);
+	tracker_sparql_builder_insert_open (sparql, uri);
 
 	tracker_sparql_builder_subject_iri (sparql, DATASOURCE_URN);
 	tracker_sparql_builder_predicate (sparql, "rdf:type");
@@ -359,7 +359,8 @@ static void
 perform_unset (TrackerKMailRegistrar *object, 
 	       const gchar *subject)
 {
-	gchar *sparql = g_strdup_printf ("DELETE { <%s> a rdfs:Resource }", subject);
+	gchar *sparql = g_strdup_printf ("DELETE FROM <%s> { <%s> a rdfs:Resource }", 
+	                                 subject, subject);
 
 	tracker_store_queue_sparql_update (sparql, NULL, NULL, NULL, NULL);
 
@@ -369,8 +370,8 @@ perform_unset (TrackerKMailRegistrar *object,
 static void
 perform_cleanup (TrackerKMailRegistrar *object)
 {
-	tracker_store_queue_sparql_update ("DELETE { ?s a rdfs:Resource } WHERE { ?s nie:dataSource <" DATASOURCE_URN "> }", NULL, NULL, NULL, NULL);
-	/* tracker_store_queue_sparql_update ("DELETE { ?s ?p ?o } WHERE { ?s nie:dataSource <" DATASOURCE_URN "> }", NULL, NULL, NULL, NULL); */
+	tracker_store_queue_sparql_update ("DELETE FROM <"DATASOURCE_URN"> { ?s a rdfs:Resource } WHERE { ?s nie:dataSource <" DATASOURCE_URN "> }", NULL, NULL, NULL, NULL);
+	/* tracker_store_queue_sparql_update ("DELETE FROM <"DATASOURCE_URN"> { ?s ?p ?o } WHERE { ?s nie:dataSource <" DATASOURCE_URN "> }", NULL, NULL, NULL, NULL); */
 }
 
 static void
diff --git a/src/tracker-extract/tracker-extract.c b/src/tracker-extract/tracker-extract.c
index 165ddd0..0404114 100644
--- a/src/tracker-extract/tracker-extract.c
+++ b/src/tracker-extract/tracker-extract.c
@@ -241,7 +241,7 @@ get_file_metadata (TrackerExtract *extract,
 	/* Create hash table to send back */
 	statements = tracker_sparql_builder_new_update ();
 
-	tracker_sparql_builder_insert_open (statements);
+	tracker_sparql_builder_insert_open (statements, uri);
 
 #ifdef HAVE_LIBSTREAMANALYZER
 	if (!priv->force_internal_extractors) {
diff --git a/src/tracker-miner-fs/tracker-miner-applications.c b/src/tracker-miner-fs/tracker-miner-applications.c
index 7dc8e12..27fef50 100644
--- a/src/tracker-miner-fs/tracker-miner-applications.c
+++ b/src/tracker-miner-fs/tracker-miner-applications.c
@@ -242,10 +242,8 @@ miner_applications_process_file_cb (gpointer user_data)
 		gchar *canonical_uri = tracker_uri_printf_escaped (SOFTWARE_CATEGORY_URN_PREFIX "%s", path);
 		gchar *icon = g_key_file_get_string (key_file, GROUP_DESKTOP_ENTRY, "Icon", NULL);
 
-		tracker_sparql_builder_insert_open (sparql);
-
 		uri = canonical_uri;
-
+		tracker_sparql_builder_insert_open (sparql, uri);
 		tracker_sparql_builder_subject_iri (sparql, uri);
 
 		tracker_sparql_builder_predicate (sparql, "a");
@@ -270,7 +268,7 @@ miner_applications_process_file_cb (gpointer user_data)
 
 	} else if (name && g_ascii_strcasecmp (type, "Application") == 0) {
 		uri = g_file_get_uri (data->file);
-		tracker_sparql_builder_insert_open (sparql);
+		tracker_sparql_builder_insert_open (sparql, uri);
 
 		tracker_sparql_builder_subject_iri (sparql, APPLICATION_DATASOURCE_URN);
 		tracker_sparql_builder_predicate (sparql, "a");
@@ -289,7 +287,7 @@ miner_applications_process_file_cb (gpointer user_data)
 	} else if (name && g_str_has_suffix (type, "Applet")) {
 		/* The URI of the InformationElement should be a UUID URN */
 		uri = g_file_get_uri (data->file);
-		tracker_sparql_builder_insert_open (sparql);
+		tracker_sparql_builder_insert_open (sparql, uri);
 
 		tracker_sparql_builder_subject_iri (sparql, APPLET_DATASOURCE_URN);
 		tracker_sparql_builder_predicate (sparql, "a");
diff --git a/src/tracker-miner-fs/tracker-miner-files.c b/src/tracker-miner-fs/tracker-miner-files.c
index 6716052..67c747b 100644
--- a/src/tracker-miner-fs/tracker-miner-files.c
+++ b/src/tracker-miner-fs/tracker-miner-files.c
@@ -466,48 +466,49 @@ set_up_mount_point (TrackerMinerFiles *miner,
 			uri = g_file_get_uri (file);
 
 			g_string_append_printf (queries,
-			                        "DROP GRAPH <%s>\nINSERT { <%s> a tracker:Volume; tracker:mountPoint <%s> } ",
-			                        removable_device_urn, removable_device_urn, uri);
+			                        "DROP GRAPH <%s>\n "
+			                        "INSERT INTO <%s> { <%s> a tracker:Volume; tracker:mountPoint <%s> } ",
+			                        removable_device_urn, removable_device_urn, removable_device_urn, uri);
 
 			g_object_unref (file);
 			g_free (uri);
 		}
 
 		g_string_append_printf (queries,
-		                        "DELETE { <%s> tracker:isMounted ?unknown } WHERE { <%s> a tracker:Volume; tracker:isMounted ?unknown } ",
-		                        removable_device_urn, removable_device_urn);
+		                        "DELETE FROM <%s> { <%s> tracker:isMounted ?unknown } WHERE { <%s> a tracker:Volume; tracker:isMounted ?unknown } ",
+		                        removable_device_urn, removable_device_urn, removable_device_urn);
 
 		g_string_append_printf (queries,
-		                        "INSERT { <%s> a tracker:Volume; tracker:isMounted true } ",
-		                        removable_device_urn);
+		                        "INSERT INTO <%s> { <%s> a tracker:Volume; tracker:isMounted true } ",
+		                        removable_device_urn, removable_device_urn);
 
 		g_string_append_printf (queries,
-		                        "INSERT { ?do tracker:available true } WHERE { ?do nie:dataSource <%s> } ",
-		                        removable_device_urn);
+		                        "INSERT INTO <%s> { ?do tracker:available true } WHERE { ?do nie:dataSource <%s> } ",
+		                        removable_device_urn, removable_device_urn);
 	} else {
 		gchar *now;
 
 		now = tracker_date_to_string (time (NULL));
 
 		g_string_append_printf (queries,
-		                        "DELETE { <%s> tracker:unmountDate ?unknown } WHERE { <%s> a tracker:Volume; tracker:unmountDate ?unknown } ",
-		                        removable_device_urn, removable_device_urn);
+		                        "DELETE FROM <%s> { <%s> tracker:unmountDate ?unknown } WHERE { <%s> a tracker:Volume; tracker:unmountDate ?unknown } ",
+		                        removable_device_urn, removable_device_urn, removable_device_urn);
 
 		g_string_append_printf (queries,
-		                        "INSERT { <%s> a tracker:Volume; tracker:unmountDate \"%s\" } ",
-		                        removable_device_urn, now);
+		                        "INSERT INTO <%s> { <%s> a tracker:Volume; tracker:unmountDate \"%s\" } ",
+		                        removable_device_urn, removable_device_urn, now);
 
 		g_string_append_printf (queries,
-		                        "DELETE { <%s> tracker:isMounted ?unknown } WHERE { <%s> a tracker:Volume; tracker:isMounted ?unknown } ",
-		                        removable_device_urn, removable_device_urn);
+		                        "DELETE FROM <%s> { <%s> tracker:isMounted ?unknown } WHERE { <%s> a tracker:Volume; tracker:isMounted ?unknown } ",
+		                        removable_device_urn, removable_device_urn, removable_device_urn);
 
 		g_string_append_printf (queries,
-		                        "INSERT { <%s> a tracker:Volume; tracker:isMounted false } ",
-		                        removable_device_urn);
+		                        "INSERT INTO <%s> { <%s> a tracker:Volume; tracker:isMounted false } ",
+		                        removable_device_urn, removable_device_urn);
 
 		g_string_append_printf (queries,
-		                        "DELETE { ?do tracker:available true } WHERE { ?do nie:dataSource <%s> } ",
-		                        removable_device_urn);
+		                        "DELETE FROM <%s> { ?do tracker:available true } WHERE { ?do nie:dataSource <%s> } ",
+		                        removable_device_urn, removable_device_urn);
 		g_free (now);
 	}
 
@@ -1279,7 +1280,7 @@ process_file_cb (GObject      *object,
 	uri = g_file_get_uri (file);
 	mime_type = g_file_info_get_content_type (file_info);
 
-        tracker_sparql_builder_insert_open (sparql);
+        tracker_sparql_builder_insert_open (sparql, uri);
 
         tracker_sparql_builder_subject_iri (sparql, uri);
 	tracker_sparql_builder_predicate (sparql, "a");



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