[tracker/anonymous-file-nodes: 26/26] Get all children URIs in a single query when moving a folder.
- From: Martyn James Russell <mr src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [tracker/anonymous-file-nodes: 26/26] Get all children URIs in a single query when moving a folder.
- Date: Wed, 3 Feb 2010 10:38:53 +0000 (UTC)
commit f68b76afa447775d2c008c0cd2ec6d11c984304a
Author: Carlos Garnacho <carlos lanedo com>
Date: Tue Feb 2 18:39:39 2010 +0100
Get all children URIs in a single query when moving a folder.
nfo:belongsToContainer isn't used since at the moment the data in there
is not actually reliable.
src/libtracker-miner/tracker-miner-fs.c | 115 +++++++++++++++----------------
1 files changed, 57 insertions(+), 58 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index 9041894..ee367b1 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -69,7 +69,6 @@ typedef struct {
typedef struct {
GMainLoop *main_loop;
- gint level;
GString *sparql;
const gchar *source_uri;
const gchar *uri;
@@ -219,7 +218,7 @@ static void crawl_directories_stop (TrackerMinerFS *fs);
static void item_queue_handlers_set_up (TrackerMinerFS *fs);
-static void item_update_uri_recursively (TrackerMinerFS *fs,
+static void item_update_children_uri (TrackerMinerFS *fs,
RecursiveMoveData *data,
const gchar *source_uri,
const gchar *uri);
@@ -1244,11 +1243,10 @@ item_writeback (TrackerMinerFS *fs,
}
static void
-item_update_uri_recursively_cb (GObject *object,
- GAsyncResult *result,
- gpointer user_data)
+item_update_children_uri_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
{
- TrackerMinerFS *fs = TRACKER_MINER_FS (object);
RecursiveMoveData *data = user_data;
GError *error = NULL;
@@ -1257,75 +1255,77 @@ item_update_uri_recursively_cb (GObject *object,
if (error) {
g_critical ("Could not query children: %s", error->message);
g_error_free (error);
- } else {
- if (query_results) {
- gint i;
-
- for (i = 0; i < query_results->len; i++) {
- GStrv row;
- gchar *child_source_uri, *child_uri, *child_mime;
-
- row = g_ptr_array_index (query_results, i);
- child_source_uri = row[0];
- child_mime = row[1];
+ } else if (query_results) {
+ gint i;
+
+ for (i = 0; i < query_results->len; i++) {
+ const gchar *child_source_uri, *child_mime, *child_urn;
+ gchar *child_uri;
+ GStrv row;
+
+ row = g_ptr_array_index (query_results, i);
+ child_urn = row[0];
+ child_source_uri = row[1];
+ child_mime = row[2];
+
+ if (!g_str_has_prefix (child_source_uri, data->source_uri)) {
+ g_warning ("Child URI '%s' does not start with parent URI '%s'",
+ child_source_uri,
+ data->source_uri);
+ continue;
+ }
- if (!g_str_has_prefix (child_source_uri, data->source_uri)) {
- g_warning ("Child URI '%s' does not start with parent URI '%s'",
- child_source_uri,
- data->source_uri);
- continue;
- }
+ child_uri = g_strdup_printf ("%s%s", data->uri, child_source_uri + strlen (data->source_uri));
- child_uri = g_strdup_printf ("%s%s", data->uri, child_source_uri + strlen (data->source_uri));
+ g_string_append_printf (data->sparql,
+ "DELETE FROM <%s> { "
+ " <%s> nie:url ?u "
+ "} WHERE { "
+ " <%s> nie:url ?u "
+ "} ",
+ child_urn, child_urn, child_urn);
- tracker_thumbnailer_move_add (child_source_uri, child_mime, child_uri);
+ g_string_append_printf (data->sparql,
+ "INSERT INTO <%s> {"
+ " <%s> nie:url '%s' "
+ "} ",
+ child_urn, child_urn, child_uri);
- item_update_uri_recursively (fs, data, child_source_uri, child_uri);
+ tracker_thumbnailer_move_add (child_source_uri, child_mime, child_uri);
- g_free (child_uri);
- }
+ g_free (child_uri);
}
}
- data->level--;
-
- g_assert (data->level >= 0);
-
- if (data->level == 0) {
- g_main_loop_quit (data->main_loop);
- }
+ g_main_loop_quit (data->main_loop);
}
static void
-item_update_uri_recursively (TrackerMinerFS *fs,
- RecursiveMoveData *move_data,
- const gchar *source_uri,
- const gchar *uri)
+item_update_children_uri (TrackerMinerFS *fs,
+ RecursiveMoveData *move_data,
+ const gchar *source_uri,
+ const gchar *uri)
{
- gchar *sparql;
-
- move_data->level++;
+ gchar *slash_uri, *sparql;
- g_string_append_printf (move_data->sparql,
- "INSERT { "
- " ?u nie:url '%s' "
- "} WHERE { "
- " ?u nie:url '%s' "
- "} ",
- uri, source_uri);
+ slash_uri = g_strconcat (source_uri, "/", NULL);
- sparql = g_strdup_printf ("SELECT ?child ?m WHERE { "
- " ?child nfo:belongsToContainer ?c . "
- " ?c nie:url '%s' . "
- " OPTIONAL { ?child nie:mimeType ?m } "
- "}",
- source_uri);
+ sparql = g_strdup_printf ("SELECT ?child ?url ?m WHERE { "
+ " ?child nie:url ?url . "
+ " OPTIONAL { "
+ " ?child nie:mimeType ?m "
+ " } . "
+ " FILTER (fn:starts-with (?url, \"%s\")) "
+ "}",
+ slash_uri);
tracker_miner_execute_sparql (TRACKER_MINER (fs),
sparql,
NULL,
- item_update_uri_recursively_cb,
+ item_update_children_uri_cb,
move_data);
+
+ g_free (slash_uri);
g_free (sparql);
}
@@ -1422,12 +1422,11 @@ item_move (TrackerMinerFS *fs,
g_free (escaped_filename);
move_data.main_loop = g_main_loop_new (NULL, FALSE);
- move_data.level = 0;
move_data.sparql = sparql;
move_data.source_uri = source_uri;
move_data.uri = uri;
- item_update_uri_recursively (fs, &move_data, source_uri, uri);
+ item_update_children_uri (fs, &move_data, source_uri, uri);
g_main_loop_run (move_data.main_loop);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]