[core] Update SQLite schema with WAL journal mode and normal sync

Offers 2×-4× performance, depending on device vintage.
This commit is contained in:
Jason Wray
2016-07-25 17:31:37 -07:00
parent eb9fe89612
commit 74f094faab
3 changed files with 17 additions and 7 deletions

View File

@@ -48,7 +48,8 @@ void OfflineDatabase::ensureSchema() {
case 0: break; // cache-only database; ok to delete
case 1: break; // cache-only database; ok to delete
case 2: migrateToVersion3(); // fall through
case 3: return;
case 3: migrateToVersion4(); // fall through
case 4: return;
default: throw std::runtime_error("unknown schema version");
}
@@ -79,8 +80,10 @@ void OfflineDatabase::ensureSchema() {
// If you change the schema you must write a migration from the previous version.
db->exec("PRAGMA auto_vacuum = INCREMENTAL");
db->exec("PRAGMA synchronous = NORMAL");
db->exec("PRAGMA journal_mode = WAL");
db->exec(schema);
db->exec("PRAGMA user_version = 3");
db->exec("PRAGMA user_version = 4");
} catch (...) {
Log::Error(Event::Database, "Unexpected error creating database schema: %s", util::toString(std::current_exception()).c_str());
throw;
@@ -111,6 +114,12 @@ void OfflineDatabase::migrateToVersion3() {
db->exec("PRAGMA user_version = 3");
}
void OfflineDatabase::migrateToVersion4() {
db->exec("PRAGMA synchronous = NORMAL");
db->exec("PRAGMA journal_mode = WAL");
db->exec("PRAGMA user_version = 4");
}
OfflineDatabase::Statement OfflineDatabase::getStatement(const char * sql) {
auto it = statements.find(sql);

View File

@@ -60,6 +60,7 @@ private:
void ensureSchema();
void removeExisting();
void migrateToVersion3();
void migrateToVersion4();
class Statement {
public: