zeitgeist team mailing list archive
-
zeitgeist team
-
Mailing list archive
-
Message #05404
[Branch ~zeitgeist/zeitgeist/bluebird] Rev 465: Merge lp:~rainct/zeitgeist/rebuild-fts-on-new-db
Merge authors:
Siegfried Gevatter (rainct)
Related merge proposals:
https://code.launchpad.net/~rainct/zeitgeist/rebuild-fts-on-new-db/+merge/101024
proposed by: Siegfried Gevatter (rainct)
review: Needs Fixing - Michal Hruby (mhr3)
------------------------------------------------------------
revno: 465 [merge]
committer: Michal Hruby <michal.mhr@xxxxxxxxx>
branch nick: zeitgeist
timestamp: Fri 2012-04-06 10:43:18 +0200
message:
Merge lp:~rainct/zeitgeist/rebuild-fts-on-new-db
modified:
extensions/fts++/controller.cpp
extensions/fts++/indexer.cpp
extensions/fts++/indexer.h
src/sql-schema.vala
--
lp:zeitgeist
https://code.launchpad.net/~zeitgeist/zeitgeist/bluebird
Your team Zeitgeist Framework Team is subscribed to branch lp:zeitgeist.
To unsubscribe from this branch go to https://code.launchpad.net/~zeitgeist/zeitgeist/bluebird/+edit-subscription
=== modified file 'extensions/fts++/controller.cpp'
--- extensions/fts++/controller.cpp 2012-04-03 18:40:44 +0000
+++ extensions/fts++/controller.cpp 2012-04-06 08:43:18 +0000
@@ -81,6 +81,11 @@
// Set the db metadata key only once we're done
PushTask (new MetadataTask ("fts_index_version", INDEX_VERSION));
+ gint64 zg_creation_date = indexer->GetZeitgeistCreationDate ();
+ gchar *creation = g_strdup_printf ("%" G_GINT64_FORMAT, zg_creation_date);
+ std::string zg_creation_date_str (creation);
+ PushTask (new MetadataTask ("zg_db_creation_date", zg_creation_date_str));
+ g_free (creation);
}
g_object_unref (time_range);
=== modified file 'extensions/fts++/indexer.cpp'
--- extensions/fts++/indexer.cpp 2012-04-03 18:40:44 +0000
+++ extensions/fts++/indexer.cpp 2012-04-05 22:34:51 +0000
@@ -146,6 +146,14 @@
}
}
+gint64 Indexer::GetZeitgeistCreationDate ()
+{
+ ZeitgeistSQLiteDatabase *database = zeitgeist_db_reader_get_database (
+ zg_reader);
+ return zeitgeist_sq_lite_database_schema_get_creation_date (
+ database->database);
+}
+
/**
* Returns true if and only if the index is good.
* Otherwise the index should be rebuild.
@@ -164,6 +172,24 @@
return false;
}
+ // Get stored Zeitgeist DB creation date
+ gint64 metadata_date;
+ std::string metadata_date_str (db->get_metadata ("zg_db_creation_date"));
+ if (metadata_date_str.empty ())
+ metadata_date = -1;
+ else
+ metadata_date = g_ascii_strtoll (metadata_date_str.c_str (), NULL, 0);
+
+ // In case the Zeitgeist DB is newer than Xapian, we need to re-build.
+ // This may happen if the Zeitgeist DB gets corrupt and is re-created
+ // from scratch.
+ gint64 database_creation_date = GetZeitgeistCreationDate ();
+ if (database_creation_date != metadata_date)
+ {
+ g_message ("Zeitgeist database has been replaced. Doing full rebuild");
+ return false;
+ }
+
return true;
}
=== modified file 'extensions/fts++/indexer.h'
--- extensions/fts++/indexer.h 2012-04-03 19:01:28 +0000
+++ extensions/fts++/indexer.h 2012-04-05 19:08:10 +0000
@@ -80,6 +80,7 @@
void IndexEvent (ZeitgeistEvent *event);
void DeleteEvent (guint32 event_id);
void SetDbMetadata (std::string const& key, std::string const& value);
+ gint64 GetZeitgeistCreationDate ();
GPtrArray* Search (const gchar *search,
ZeitgeistTimeRange *time_range,
=== modified file 'src/sql-schema.vala'
--- src/sql-schema.vala 2012-04-05 12:12:49 +0000
+++ src/sql-schema.vala 2012-04-05 20:07:23 +0000
@@ -38,6 +38,8 @@
public const string CORE_SCHEMA = "core";
public const int CORE_SCHEMA_VERSION = 6;
+ private const string DATABASE_CREATION = "database_creation";
+
public static void ensure_schema (Sqlite.Database database)
throws EngineError
{
@@ -48,6 +50,12 @@
{
// most likely a new DB
create_schema (database);
+
+ // set database creation date
+ var schema_sql = ("INSERT INTO schema_version VALUES ('%s', %" +
+ int64.FORMAT + ")").printf (DATABASE_CREATION,
+ Timestamp.now ());
+ exec_query (database, schema_sql);
}
else if (schema_version == 4 || schema_version == 5)
{
@@ -123,28 +131,44 @@
public static int get_schema_version (Sqlite.Database database)
throws EngineError
{
- var sql = "SELECT version FROM schema_version WHERE schema='core'";
- int schema_version = -1;
- database.exec (sql,
- (n_cols, values, column_names) =>
- {
- if (values[0] != null)
- {
- schema_version = int.parse (values[0]);
- }
- return 0;
- }, null);
-
- // we don't really care about the return value of exec, the result
- // will be -1 if something went wrong anyway
- debug ("schema_version is %d", schema_version);
-
- if (schema_version < -1)
- {
- throw new EngineError.DATABASE_CORRUPT (
- "Database corruption flag is set.");
- }
- return schema_version;
+ int schema_version = (int) get_schema_metadata (database, CORE_SCHEMA);
+ debug ("schema_version is %d", schema_version);
+
+ if (schema_version < -1)
+ {
+ throw new EngineError.DATABASE_CORRUPT (
+ "Database corruption flag is set.");
+ }
+ return schema_version;
+ }
+
+ public static int64 get_creation_date (Sqlite.Database database)
+ {
+ return get_schema_metadata (database, DATABASE_CREATION);
+ }
+
+ private static int64 get_schema_metadata (Sqlite.Database database,
+ string key)
+ {
+ var sql = "SELECT version FROM schema_version " +
+ "WHERE schema='%s'".printf (key);
+
+ int64 schema_version = -1;
+
+ database.exec (sql,
+ (n_cols, values, column_names) =>
+ {
+ if (values[0] != null)
+ {
+ schema_version = int64.parse (values[0]);
+ }
+ return 0;
+ }, null);
+
+ // we don't really care about the return value of exec, the result
+ // will be -1 if something went wrong anyway
+
+ return schema_version;
}
public static void set_corruption_flag (Sqlite.Database database)