[tracker] Changed tracker:modified into a modification sequence instead of time()



commit b5bc4511b92148aaaeb3471bd61e3501e567cf68
Author: Philip Van Hoof <philip codeminded be>
Date:   Fri Aug 14 12:13:44 2009 +0200

    Changed tracker:modified into a modification sequence instead of time()

 src/libtracker-data/tracker-data-manager.c         |   32 ++++++++++++++++----
 src/libtracker-data/tracker-data-manager.h         |    7 ++--
 src/libtracker-data/tracker-data-update.c          |   17 +++++++++-
 src/libtracker-data/tracker-data-update.h          |    3 ++
 src/plugins/evolution/tracker-evolution-plugin.c   |    6 ++--
 .../evolution/tracker-evolution-registrar.c        |    6 ++--
 src/plugins/kmail/tracker-kmail-registrar.c        |    6 ++--
 7 files changed, 57 insertions(+), 20 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 7595243..773fef8 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -27,6 +27,7 @@
 #include <stdlib.h>
 #include <fcntl.h>
 #include <zlib.h>
+#include <inttypes.h>
 
 #include <glib/gstdio.h>
 
@@ -65,6 +66,21 @@ static gchar		  *ontologies_dir;
 static gboolean            initialized;
 
 static void
+tracker_data_store_modseq (void)
+{
+	tracker_data_manager_set_db_option_int64 ("ModificationSequence", 
+	                                          tracker_data_get_modification_sequence ());
+
+}
+
+static void
+tracker_data_restore_modseq (void)
+{
+	tracker_data_set_modification_sequence (tracker_data_manager_get_db_option_int64 ("ModificationSequence"));
+}
+
+
+static void
 load_ontology_file_from_path (const gchar	 *ontology_file)
 {
 	tracker_turtle_reader_init (ontology_file, NULL);
@@ -859,23 +875,27 @@ tracker_data_manager_init (TrackerDBManagerFlags       flags,
 		create_decomposed_transient_metadata_tables (iface);
 	}
 
+	tracker_data_restore_modseq ();
+
 	initialized = TRUE;
 
 	return TRUE;
 }
 
+
 void
 tracker_data_manager_shutdown (void)
 {
 	g_return_if_fail (initialized == TRUE);
 
+	tracker_data_store_modseq ();
 	tracker_db_manager_shutdown ();
 
 	initialized = FALSE;
 }
 
-gint
-tracker_data_manager_get_db_option_int (const gchar *option)
+gint64
+tracker_data_manager_get_db_option_int64 (const gchar *option)
 {
 	TrackerDBInterface *iface;
 	TrackerDBStatement *stmt;
@@ -896,7 +916,7 @@ tracker_data_manager_get_db_option_int (const gchar *option)
 		tracker_db_result_set_get (result_set, 0, &str, -1);
 
 		if (str) {
-			value = atoi (str);
+			value = g_ascii_strtoull (str, NULL, 10);
 			g_free (str);
 		}
 
@@ -907,8 +927,8 @@ tracker_data_manager_get_db_option_int (const gchar *option)
 }
 
 void
-tracker_data_manager_set_db_option_int (const gchar *option,
-					gint	     value)
+tracker_data_manager_set_db_option_int64 (const gchar *option,
+					  gint64       value)
 {
 	TrackerDBInterface *iface;
 	TrackerDBStatement *stmt;
@@ -921,7 +941,7 @@ tracker_data_manager_set_db_option_int (const gchar *option,
 	stmt = tracker_db_interface_create_statement (iface, "REPLACE INTO Options (OptionKey, OptionValue) VALUES (?,?)");
 	tracker_db_statement_bind_text (stmt, 0, option);
 
-	str = tracker_gint_to_string (value);
+	str = g_strdup_printf ("%"G_GINT64_FORMAT, value);
 	tracker_db_statement_bind_text (stmt, 1, str);
 	g_free (str);
 
diff --git a/src/libtracker-data/tracker-data-manager.h b/src/libtracker-data/tracker-data-manager.h
index 012a6c2..e0cfe40 100644
--- a/src/libtracker-data/tracker-data-manager.h
+++ b/src/libtracker-data/tracker-data-manager.h
@@ -39,9 +39,10 @@ gboolean            tracker_data_manager_init              (TrackerDBManagerFlag
 							    gboolean                   *first_time);
 void                tracker_data_manager_shutdown          (void);
 
-gint                tracker_data_manager_get_db_option_int (const gchar        *option);
-void                tracker_data_manager_set_db_option_int (const gchar        *option,
-							    gint                value);
+gint64              tracker_data_manager_get_db_option_int64 (const gchar        *option);
+void                tracker_data_manager_set_db_option_int64 (const gchar        *option,
+							      gint64              value);
+
 
 G_END_DECLS
 
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index 673d864..011001d 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -88,6 +88,19 @@ static TrackerStatementCallback delete_callback = NULL;
 static gpointer delete_data;
 static TrackerCommitCallback commit_callback = NULL;
 static gpointer commit_data;
+static gint64 modification_sequence;
+
+gint64
+tracker_data_get_modification_sequence (void)
+{
+	return modification_sequence;
+}
+
+void
+tracker_data_set_modification_sequence (gint64 modseq)
+{
+	modification_sequence = modseq;
+}
 
 void 
 tracker_data_set_commit_statement_callback (TrackerCommitCallback    callback,
@@ -256,7 +269,7 @@ ensure_resource_id (const gchar *uri)
 		stmt = tracker_db_interface_create_statement (iface, "INSERT INTO \"rdfs:Resource\" (ID, Uri, \"tracker:modified\", Available) VALUES (?, ?, ?, 1)");
 		tracker_db_statement_bind_int (stmt, 0, id);
 		tracker_db_statement_bind_text (stmt, 1, uri);
-		tracker_db_statement_bind_int64 (stmt, 2, (gint64) time(NULL));
+		tracker_db_statement_bind_int64 (stmt, 2, ++modification_sequence);
 		tracker_db_statement_execute (stmt, NULL);
 		g_object_unref (stmt);
 
@@ -1004,7 +1017,7 @@ tracker_data_insert_statement_common (const gchar            *subject,
 		update_buffer.id = ensure_resource_id (update_buffer.subject);
 		update_buffer.types = tracker_data_query_rdf_type (update_buffer.id);
 
-		g_value_set_int64 (&gvalue, (gint64) time (NULL));
+		g_value_set_int64 (&gvalue, ++modification_sequence);
 		cache_insert_value ("rdfs:Resource", "tracker:modified", &gvalue, FALSE, FALSE);
 	}
 
diff --git a/src/libtracker-data/tracker-data-update.h b/src/libtracker-data/tracker-data-update.h
index d9215b1..aac85f1 100644
--- a/src/libtracker-data/tracker-data-update.h
+++ b/src/libtracker-data/tracker-data-update.h
@@ -69,6 +69,9 @@ void     tracker_data_commit_transaction		(void);
 void     tracker_data_update_sparql			(const gchar       *update,
 							 GError	          **error);
 
+gint64    tracker_data_get_modification_sequence         (void);
+void      tracker_data_set_modification_sequence        (gint64 modseq);
+
 /* Volume handling */
 void tracker_data_update_enable_volume                  (const gchar         *udi,
                                                          const gchar         *mount_path);
diff --git a/src/plugins/evolution/tracker-evolution-plugin.c b/src/plugins/evolution/tracker-evolution-plugin.c
index 50a1a20..5ea9a8a 100644
--- a/src/plugins/evolution/tracker-evolution-plugin.c
+++ b/src/plugins/evolution/tracker-evolution-plugin.c
@@ -384,7 +384,7 @@ on_folder_summary_changed (CamelFolder *folder,
 				flags =   (guint)   camel_message_info_flags (linfo);
 
 				/* Camel returns a time_t, I think a uint64 is the best fit here */
-				sent = g_strdup_printf ("%"PRIu64, (guint64) camel_message_info_date_sent (linfo));
+				sent = g_strdup_printf ("%"G_GUINT64_FORMAT, (guint64) camel_message_info_date_sent (linfo));
 
 				/* Camel returns a uint32, so %u */
 				size = g_strdup_printf ("%u", camel_message_info_size (linfo));
@@ -633,7 +633,7 @@ introduce_walk_folders_in_folder (TrackerEvolutionPlugin *self,
 					        "mail_from, mail_to, mail_cc, mlist, "   /* 12 - 15 */
 					        "labels, usertags "                      /* 16 - 17 */
 					 "FROM %Q "
-					 "WHERE modified > %"PRIu64, 
+					 "WHERE modified > %"G_GUINT64_FORMAT, 
 
 					 iter->full_name, 
 					 info->last_checkout);
@@ -859,7 +859,7 @@ introduce_store_deal_with_deleted (TrackerEvolutionPlugin *self,
 	guint i, ret;
 	gchar *em_uri = em_uri_from_camel (account_uri);
 
-	query = sqlite3_mprintf ("SELECT uid, mailbox FROM Deletes WHERE modified > %" PRIu64, 
+	query = sqlite3_mprintf ("SELECT uid, mailbox FROM Deletes WHERE modified > %" G_GUINT64_FORMAT, 
 				 info->last_checkout);
 
 	/* This creates a thread apparently */
diff --git a/src/plugins/evolution/tracker-evolution-registrar.c b/src/plugins/evolution/tracker-evolution-registrar.c
index eb1f768..4b7ee3f 100644
--- a/src/plugins/evolution/tracker-evolution-registrar.c
+++ b/src/plugins/evolution/tracker-evolution-registrar.c
@@ -615,7 +615,7 @@ perform_cleanup (TrackerEvolutionRegistrar *object)
 static void
 set_stored_last_modseq (guint last_modseq)
 {
-	tracker_data_manager_set_db_option_int ("EvolutionLastModseq", (gint) last_modseq);
+	tracker_data_manager_set_db_option_int64 ("EvolutionLastModseq", (gint64) last_modseq);
 }
 
 static void
@@ -837,10 +837,10 @@ tracker_evolution_push_registrar_enable (TrackerPushRegistrar *registrar,
 					     TRACKER_EVOLUTION_REGISTRAR_PATH, 
 					     object);
 
-	/* Registration of the registrar to the manager */
+	/* Registration of the registrar to the manager - the cast is fine and checked */
 	dbus_g_proxy_call_no_reply (manager_proxy, "Register",
 				    G_TYPE_OBJECT, object, 
-				    G_TYPE_UINT, (guint) tracker_data_manager_get_db_option_int ("EvolutionLastModseq"),
+				    G_TYPE_UINT, (guint) tracker_data_manager_get_db_option_int64 ("EvolutionLastModseq"),
 				    G_TYPE_INVALID,
 				    G_TYPE_INVALID);
 
diff --git a/src/plugins/kmail/tracker-kmail-registrar.c b/src/plugins/kmail/tracker-kmail-registrar.c
index f011305..3705987 100644
--- a/src/plugins/kmail/tracker-kmail-registrar.c
+++ b/src/plugins/kmail/tracker-kmail-registrar.c
@@ -376,7 +376,7 @@ perform_cleanup (TrackerKMailRegistrar *object)
 static void
 set_stored_last_modseq (guint last_modseq)
 {
-	tracker_data_manager_set_db_option_int ("KMailLastModseq", (gint) last_modseq);
+	tracker_data_manager_set_db_option_int64 ("KMailLastModseq", (gint64) last_modseq);
 }
 
 
@@ -601,10 +601,10 @@ tracker_kmail_push_registrar_enable (TrackerPushRegistrar *registrar,
 					     TRACKER_KMAIL_REGISTRAR_PATH, 
 					     object);
 
-	/* Registration of the registrar to the manager */
+	/* Registration of the registrar to the manager - the cast is fine and checked */
 	dbus_g_proxy_call_no_reply (manager_proxy, "Register",
 				    G_TYPE_OBJECT, object, 
-				    G_TYPE_UINT, (guint) tracker_data_manager_get_db_option_int ("KMailLastModseq"),
+				    G_TYPE_UINT, (guint) tracker_data_manager_get_db_option_int64 ("KMailLastModseq"),
 				    G_TYPE_INVALID,
 				    G_TYPE_INVALID);
 



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