summaryrefslogtreecommitdiff
path: root/platform/default/mbgl/storage/offline_database.cpp
diff options
context:
space:
mode:
authorJason Wray <jason@mapbox.com>2016-07-25 17:31:37 -0700
committerJason Wray <jason@mapbox.com>2016-08-23 13:26:02 -0400
commit74f094faabb3cf0e031c13f85116be69172cd69e (patch)
treea83193eb3c66b97cdee0ef0672531e3c2ddf7b3d /platform/default/mbgl/storage/offline_database.cpp
parenteb9fe89612d0effca9e547deedcbe702953570b8 (diff)
downloadqtlocation-mapboxgl-74f094faabb3cf0e031c13f85116be69172cd69e.tar.gz
[core] Update SQLite schema with WAL journal mode and normal sync
Offers 2×-4× performance, depending on device vintage.
Diffstat (limited to 'platform/default/mbgl/storage/offline_database.cpp')
-rw-r--r--platform/default/mbgl/storage/offline_database.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/platform/default/mbgl/storage/offline_database.cpp b/platform/default/mbgl/storage/offline_database.cpp
index 46a2c2bc25..d93b1734b4 100644
--- a/platform/default/mbgl/storage/offline_database.cpp
+++ b/platform/default/mbgl/storage/offline_database.cpp
@@ -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);