zeitgeist team mailing list archive
-
zeitgeist team
-
Mailing list archive
-
Message #05396
[Merge] lp:~rainct/zeitgeist/rebuild-fts-on-new-db into lp:zeitgeist
Siegfried Gevatter has proposed merging lp:~rainct/zeitgeist/rebuild-fts-on-new-db into lp:zeitgeist.
Requested reviews:
Zeitgeist Framework Team (zeitgeist)
For more details, see:
https://code.launchpad.net/~rainct/zeitgeist/rebuild-fts-on-new-db/+merge/101024
--
https://code.launchpad.net/~rainct/zeitgeist/rebuild-fts-on-new-db/+merge/101024
Your team Zeitgeist Framework Team is requested to review the proposed merge of lp:~rainct/zeitgeist/rebuild-fts-on-new-db into lp:zeitgeist.
=== modified file 'extensions/fts++/controller.cpp'
--- extensions/fts++/controller.cpp 2012-04-03 18:40:44 +0000
+++ extensions/fts++/controller.cpp 2012-04-05 19:10:22 +0000
@@ -17,6 +17,8 @@
*/
#include "controller.h"
+#include <string>
+#include <sstream>
namespace ZeitgeistFTS {
@@ -81,6 +83,12 @@
// Set the db metadata key only once we're done
PushTask (new MetadataTask ("fts_index_version", INDEX_VERSION));
+ gint64 zg_creation_date = indexer->GetZeitgeistCreationDate ();
+ std::stringstream tmpstream;
+ std::string zg_creation_date_str;
+ tmpstream << zg_creation_date;
+ tmpstream >> zg_creation_date_str;
+ PushTask (new MetadataTask ("zg_db_creation_date", zg_creation_date_str));
}
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 19:10:22 +0000
@@ -23,6 +23,8 @@
#include <xapian.h>
#include <queue>
#include <vector>
+#include <string>
+#include <sstream>
#include <gio/gio.h>
#include <gio/gdesktopappinfo.h>
@@ -146,6 +148,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 +174,28 @@
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 == "")
+ metadata_date = -1;
+ else
+ {
+ std::stringstream tmpstream;
+ tmpstream << metadata_date_str;
+ tmpstream >> metadata_date;
+ }
+
+ // 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:10:22 +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 19:10:22 +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,11 @@
{
// most likely a new DB
create_schema (database);
+
+ // set database creation date
+ var schema_sql = "INSERT INTO schema_version VALUES ('%s', %l64d)"
+ .printf (DATABASE_CREATION, Timestamp.now ());
+ exec_query (database, schema_sql);
}
else if (schema_version == 4 || schema_version == 5)
{
@@ -123,28 +130,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)
Follow ups