[tracker] tracker-indexer: Fix file update check



commit 9f1331f5a88a502b0b135c5fa740b0e95d133673
Author: Jürg Billeter <j bitron ch>
Date:   Mon Apr 27 12:08:32 2009 +0200

    tracker-indexer: Fix file update check
---
 src/libtracker-data/tracker-data-query.c          |   17 ++----
 src/libtracker-data/tracker-data-query.h          |    5 +-
 src/plugins/evolution/tracker-evolution-indexer.c |    2 +-
 src/plugins/kmail/tracker-kmail-indexer.c         |    2 +-
 src/tracker-indexer/modules/applications.c        |    6 +-
 src/tracker-indexer/tracker-indexer.c             |   58 ++++++++++-----------
 6 files changed, 40 insertions(+), 50 deletions(-)

diff --git a/src/libtracker-data/tracker-data-query.c b/src/libtracker-data/tracker-data-query.c
index c6fbe1e..9819e61 100644
--- a/src/libtracker-data/tracker-data-query.c
+++ b/src/libtracker-data/tracker-data-query.c
@@ -278,22 +278,20 @@ tracker_data_query_resource_id (const gchar	   *uri)
 
 gboolean
 tracker_data_query_resource_exists (const gchar	  *uri,
-				   guint32	  *service_id,
-				   time_t	  *mtime)
+				   guint32	  *resource_id)
 {
 	TrackerDBInterface *iface;
 	TrackerDBStatement *stmt;
 	TrackerDBResultSet *result_set;
 	guint db_id;
-	guint db_mtime;
 	gboolean found = FALSE;
 
-	db_id = db_mtime = 0;
+	db_id = 0;
 
 	iface = tracker_db_manager_get_db_interface ();
 
 	stmt = tracker_db_interface_create_statement (iface,
-		"SELECT ID, Modified FROM \"rdfs:Resource\" WHERE Uri = ?");
+		"SELECT ID FROM \"rdfs:Resource\" WHERE Uri = ?");
 	tracker_db_statement_bind_text (stmt, 0, uri);
 	result_set = tracker_db_statement_execute (stmt, NULL);
 	g_object_unref (stmt);
@@ -301,18 +299,13 @@ tracker_data_query_resource_exists (const gchar	  *uri,
 	if (result_set) {
 		tracker_db_result_set_get (result_set,
 					   0, &db_id,
-					   1, &db_mtime,
 					   -1);
 		g_object_unref (result_set);
 		found = TRUE;
 	}
 
-	if (service_id) {
-		*service_id = (guint32) db_id;
-	}
-
-	if (mtime) {
-		*mtime = (time_t) db_mtime;
+	if (resource_id) {
+		*resource_id = (guint32) db_id;
 	}
 
 	return found;
diff --git a/src/libtracker-data/tracker-data-query.h b/src/libtracker-data/tracker-data-query.h
index ab29e83..de9dd5e 100644
--- a/src/libtracker-data/tracker-data-query.h
+++ b/src/libtracker-data/tracker-data-query.h
@@ -49,9 +49,8 @@ TrackerDBResultSet  *tracker_data_query_backup_metadata       (TrackerService
 							       TrackerProperty        *field_def);
 #endif
 
-gboolean             tracker_data_query_resource_exists        (const gchar         *uri,
-							       guint32             *service_id,
-							       time_t              *mtime);
+gboolean             tracker_data_query_resource_exists        (const gchar        *uri,
+							       guint32             *resource_id);
 
 guint32              tracker_data_query_resource_id           (const gchar         *uri);
 
diff --git a/src/plugins/evolution/tracker-evolution-indexer.c b/src/plugins/evolution/tracker-evolution-indexer.c
index 113c828..d74ae7b 100644
--- a/src/plugins/evolution/tracker-evolution-indexer.c
+++ b/src/plugins/evolution/tracker-evolution-indexer.c
@@ -260,7 +260,7 @@ perform_set (TrackerEvolutionIndexer *object,
 {
 	guint i = 0;
 
-	if (!tracker_data_query_resource_exists (DATASOURCE_URN, NULL, NULL)) {
+	if (!tracker_data_query_resource_exists (DATASOURCE_URN, NULL)) {
 		tracker_data_insert_statement (DATASOURCE_URN, RDF_TYPE,
 					       NIE_DATASOURCE);
 	}
diff --git a/src/plugins/kmail/tracker-kmail-indexer.c b/src/plugins/kmail/tracker-kmail-indexer.c
index d0bb597..eb49216 100644
--- a/src/plugins/kmail/tracker-kmail-indexer.c
+++ b/src/plugins/kmail/tracker-kmail-indexer.c
@@ -162,7 +162,7 @@ perform_set (TrackerKMailIndexer *object,
 {
 	guint i = 0;
 
-	if (!tracker_data_query_resource_exists (DATASOURCE_URN, NULL, NULL)) {
+	if (!tracker_data_query_resource_exists (DATASOURCE_URN, NULL)) {
 		tracker_data_insert_statement (DATASOURCE_URN, RDF_TYPE,
 					       NIE_DATASOURCE);
 	}
diff --git a/src/tracker-indexer/modules/applications.c b/src/tracker-indexer/modules/applications.c
index 2ad3aff..2e7cdda 100644
--- a/src/tracker-indexer/modules/applications.c
+++ b/src/tracker-indexer/modules/applications.c
@@ -201,7 +201,7 @@ tracker_application_file_get_metadata (TrackerModuleFile *file)
 
 		tracker_module_metadata_add_string (metadata, uri, RDF_TYPE, NFO_PREFIX "SoftwareApplication");
 
-		if (!tracker_data_query_resource_exists (APPLICATION_DATASOURCE_URN, NULL, NULL)) {
+		if (!tracker_data_query_resource_exists (APPLICATION_DATASOURCE_URN, NULL)) {
 			tracker_module_metadata_add_string (metadata, APPLICATION_DATASOURCE_URN, 
 							    RDF_TYPE, NIE_PREFIX "DataSource");
 		}
@@ -218,7 +218,7 @@ tracker_application_file_get_metadata (TrackerModuleFile *file)
 		/* TODO This is atm specific for Maemo */
 		tracker_module_metadata_add_string (metadata, uri, RDF_TYPE, MAEMO_PREFIX "SoftwareApplet");
 
-		if (!tracker_data_query_resource_exists (APPLET_DATASOURCE_URN, NULL, NULL)) {
+		if (!tracker_data_query_resource_exists (APPLET_DATASOURCE_URN, NULL)) {
 			tracker_module_metadata_add_string (metadata, APPLET_DATASOURCE_URN, 
 							    RDF_TYPE, NIE_PREFIX "DataSource");
 		}
@@ -254,7 +254,7 @@ tracker_application_file_get_metadata (TrackerModuleFile *file)
 			for (i = 0 ; cats[i] && i < cats_len ; i++) {
 				gchar *cat_uri = tracker_uri_printf_escaped (SOFTWARE_CATEGORY_URN_PREFIX "%s", cats[i]);
 
-				if (!tracker_data_query_resource_exists (cat_uri, NULL, NULL)) {
+				if (!tracker_data_query_resource_exists (cat_uri, NULL)) {
 
 					/* Oeps, first time we see the category, there are also .desktop
 					 * files that describe these categories, but we can handle 
diff --git a/src/tracker-indexer/tracker-indexer.c b/src/tracker-indexer/tracker-indexer.c
index 1e44beb..f97fa7a 100644
--- a/src/tracker-indexer/tracker-indexer.c
+++ b/src/tracker-indexer/tracker-indexer.c
@@ -1138,7 +1138,7 @@ item_add_to_datasource (TrackerIndexer *indexer,
 		removable_device_urn = g_strdup_printf (TRACKER_DATASOURCE_URN_PREFIX "%s", 
 						        removable_device_udi);
 
-		if (!tracker_data_query_resource_exists (removable_device_urn, NULL, NULL)) {
+		if (!tracker_data_query_resource_exists (removable_device_urn, NULL)) {
 			tracker_data_insert_statement (removable_device_urn, 
 						       RDF_TYPE, TRACKER_DATASOURCE);
 		}
@@ -1148,7 +1148,7 @@ item_add_to_datasource (TrackerIndexer *indexer,
 
 		g_free (removable_device_urn);
 	} else {
-		if (!tracker_data_query_resource_exists (TRACKER_NON_REMOVABLE_MEDIA_DATASOURCE_URN, NULL, NULL)) {
+		if (!tracker_data_query_resource_exists (TRACKER_NON_REMOVABLE_MEDIA_DATASOURCE_URN, NULL)) {
 			tracker_data_insert_statement (TRACKER_NON_REMOVABLE_MEDIA_DATASOURCE_URN, 
 						       RDF_TYPE, TRACKER_DATASOURCE);
 		}
@@ -1168,7 +1168,7 @@ item_add_or_update (TrackerIndexer        *indexer,
 	guint32 id;
 	gchar *mount_point = NULL;
 
-	if (tracker_data_query_resource_exists (uri, &id, NULL)) {
+	if (tracker_data_query_resource_exists (uri, &id)) {
 		gchar *old_text;
 
 		if (tracker_module_file_get_flags (info->module_file) & TRACKER_FILE_CONTENTS_STATIC) {
@@ -1317,8 +1317,7 @@ item_move (TrackerIndexer  *indexer,
 
 	/* Get 'source' ID */
 	if (!tracker_data_query_resource_exists (source_uri,
-					       &service_id,
-					       NULL)) {
+					       &service_id)) {
 		gboolean res;
 
 		g_message ("Source file '%s' not found in database to move, indexing '%s' from scratch", source_uri, uri);
@@ -1392,13 +1391,13 @@ item_remove (TrackerIndexer *indexer,
 		/* The file is not anymore in the filesystem. Obtain
 		 * the service type from the DB.
 		 */
-		if (!tracker_data_query_resource_exists (uri, NULL, NULL)) {
+		if (!tracker_data_query_resource_exists (uri, NULL)) {
 			/* File didn't exist, nothing to delete */
 			return;
 		}
 	}
 
-	tracker_data_query_resource_exists (uri, &service_id, NULL);
+	tracker_data_query_resource_exists (uri, &service_id);
 
 	if (service_id < 1) {
 		g_debug ("  File does not exist anyway "
@@ -1529,9 +1528,7 @@ handle_metadata_add (TrackerIndexer *indexer,
 		return FALSE;
 	}
 
-	tracker_data_query_resource_exists (uri,
-					  &service_id,
-					  NULL);
+	tracker_data_query_resource_exists (uri, &service_id);
 
 	if (service_id < 1) {
 		g_set_error (error,
@@ -1580,25 +1577,13 @@ should_change_index_for_file (TrackerIndexer *indexer,
 			      PathInfo       *info,
 			      const gchar    *uri)
 {
-	GFileInfo *file_info;
-	time_t mtime;
-
-	/* Check the file/directory exists. If it doesn't we
-	 * definitely want to index it.
-	 */
-	if (!tracker_data_query_resource_exists (uri,
-					       NULL,
-					       &mtime)) {
-		return TRUE;
-	}
+	TrackerDBResultSet *result_set;
+	GFileInfo          *file_info;
+	time_t              mtime;
+	struct tm           t;
+	gchar               *query;
 
-	/* So, if we are here, then the file or directory DID exist
-	 * in the database already. Now we need to check if the
-	 * parent directory mtime matches the mtime we have for it in
-	 * the database. If it does, then we can ignore any files
-	 * immediately in this parent directory.
-	 */
-	file_info = g_file_query_info (info->file, "standard::*", G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, NULL);
+	file_info = g_file_query_info (info->file, G_FILE_ATTRIBUTE_TIME_MODIFIED, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, NULL);
 	if (!file_info) {
 		/* NOTE: We return TRUE here because we want to update the DB
 		 * about this file, not because we want to index it.
@@ -1606,12 +1591,25 @@ should_change_index_for_file (TrackerIndexer *indexer,
 		return TRUE;
 	}
 
-	if (g_file_info_get_attribute_uint64 (file_info, G_FILE_ATTRIBUTE_TIME_MODIFIED) == mtime) {
-		g_message ("%s: is already up to date in DB, not (re)indexing", uri);
+	mtime = g_file_info_get_attribute_uint64 (file_info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
+	g_object_unref (file_info);
+
+	gmtime_r (&mtime, &t);
+
+	query = g_strdup_printf ("SELECT ?file { ?file nfo:fileLastModified \"%04d-%02d-%02dT%02d:%02d:%02d\" . FILTER (?file = <%s>) }",
+	                         t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec, uri);
+	result_set = tracker_data_query_sparql (query, NULL);
+	g_free (query);
 
+	if (result_set) {
+		/* File already up-to-date in the database */
+		g_object_unref (result_set);
 		return FALSE;
 	}
 
+	/* File either not yet in the database or mtime is different
+	 * Update in database required
+	 */
 	return TRUE;
 }
 



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