From 4146d8d9be3a732a626b0e537ed1490af9bc0427 Mon Sep 17 00:00:00 2001 From: Ivo van Dongen Date: Thu, 22 Feb 2018 13:37:59 +0200 Subject: [core] offline database - move transaction scope to public api level --- platform/default/mbgl/storage/offline_database.cpp | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/platform/default/mbgl/storage/offline_database.cpp b/platform/default/mbgl/storage/offline_database.cpp index 2b872ab87b..d2e1fe8ec1 100644 --- a/platform/default/mbgl/storage/offline_database.cpp +++ b/platform/default/mbgl/storage/offline_database.cpp @@ -175,7 +175,10 @@ optional OfflineDatabase::hasInternal(const Resource& resource) { } std::pair OfflineDatabase::put(const Resource& resource, const Response& response) { - return putInternal(resource, response, true); + mapbox::sqlite::Transaction transaction(*db, mapbox::sqlite::Transaction::Immediate); + auto result = putInternal(resource, response, true); + transaction.commit(); + return result; } std::pair OfflineDatabase::putInternal(const Resource& resource, const Response& response, bool evict_) { @@ -292,11 +295,6 @@ bool OfflineDatabase::putResource(const Resource& resource, } // We can't use REPLACE because it would change the id value. - - // Begin an immediate-mode transaction to ensure that two writers do not attempt - // to INSERT a resource at the same moment. - mapbox::sqlite::Transaction transaction(*db, mapbox::sqlite::Transaction::Immediate); - // clang-format off mapbox::sqlite::Query updateQuery{ getStatement( "UPDATE resources " @@ -329,7 +327,6 @@ bool OfflineDatabase::putResource(const Resource& resource, updateQuery.run(); if (updateQuery.changes() != 0) { - transaction.commit(); return false; } @@ -356,7 +353,6 @@ bool OfflineDatabase::putResource(const Resource& resource, } insertQuery.run(); - transaction.commit(); return true; } @@ -484,10 +480,6 @@ bool OfflineDatabase::putTile(const Resource::TileData& tile, // We can't use REPLACE because it would change the id value. - // Begin an immediate-mode transaction to ensure that two writers do not attempt - // to INSERT a resource at the same moment. - mapbox::sqlite::Transaction transaction(*db, mapbox::sqlite::Transaction::Immediate); - // clang-format off mapbox::sqlite::Query updateQuery{ getStatement( "UPDATE tiles " @@ -526,7 +518,6 @@ bool OfflineDatabase::putTile(const Resource::TileData& tile, updateQuery.run(); if (updateQuery.changes() != 0) { - transaction.commit(); return false; } @@ -556,7 +547,6 @@ bool OfflineDatabase::putTile(const Resource::TileData& tile, } insertQuery.run(); - transaction.commit(); return true; } -- cgit v1.2.1