[tracker] TrackerMinerFS: Fix mtime cache for crawl directories themselves.



commit d3cf67b05a46f7727d0836d9dd151b51a542332f
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu May 20 14:20:40 2010 +0200

    TrackerMinerFS: Fix mtime cache for crawl directories themselves.
    
    Mtime cache works by querying the parent folder, but for crawl directories
    there wouldn't be any data for its parent folder, needlessly reindexing
    these again, and leaving orphaned urns in the database. This problem would
    add up in consecutive runs, as direct children nfo:belongsToContainer would
    still point to the orphaned node, thus spreading the problem through the
    hierarchy.

 src/libtracker-miner/tracker-miner-fs.c |   50 ++++++++++++++++++++++++++++++-
 1 files changed, 49 insertions(+), 1 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index 6bf2a0c..3986a1b 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -2155,6 +2155,29 @@ item_queue_handlers_set_up (TrackerMinerFS *fs)
 		                   fs);
 }
 
+static gboolean
+file_is_crawl_directory (TrackerMinerFS *fs,
+                         GFile          *file)
+{
+	GList *dirs;
+
+	/* Check whether file is a crawl directory itself */
+	dirs = fs->private->config_directories;
+
+	while (dirs) {
+		DirectoryData *data;
+
+		data = dirs->data;
+		dirs = dirs->next;
+
+		if (g_file_equal (data->file, file)) {
+			return TRUE;
+		}
+	}
+
+	return FALSE;
+}
+
 static void
 ensure_mtime_cache (TrackerMinerFS *fs,
                     GFile          *file)
@@ -2205,12 +2228,37 @@ ensure_mtime_cache (TrackerMinerFS *fs,
 	                              NULL,
 	                              cache_query_cb,
 	                              &data);
+	g_free (query);
 
 	g_main_loop_run (data.main_loop);
 
+	if (g_hash_table_size (data.values) == 0 &&
+	    file_is_crawl_directory (fs, file)) {
+		/* File is a crawl directory itself, query its mtime directly */
+		uri = g_file_get_uri (file);
+
+		g_debug ("Folder %s is a crawl directory, generating mtime cache for it", uri);
+
+		query = g_strdup_printf ("SELECT ?url ?last "
+		                         "WHERE { "
+		                         "  ?u nfo:fileLastModified ?last ; "
+		                         "     nie:url ?url ; "
+		                         "     nie:url \"%s\" "
+		                         "}", uri);
+		g_free (uri);
+
+		tracker_miner_execute_sparql (TRACKER_MINER (fs),
+		                              query,
+		                              NULL,
+		                              cache_query_cb,
+		                              &data);
+		g_free (query);
+
+		g_main_loop_run (data.main_loop);
+        }
+
 	g_main_loop_unref (data.main_loop);
 	g_hash_table_unref (data.values);
-	g_free (query);
 }
 
 static gboolean



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