Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] offline database - move transaction scope to public api level
Browse files Browse the repository at this point in the history
  • Loading branch information
ivovandongen committed Jun 4, 2018
1 parent be66de6 commit 3f22443
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions platform/default/mbgl/storage/offline_database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ optional<int64_t> OfflineDatabase::hasInternal(const Resource& resource) {
}

std::pair<bool, uint64_t> 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<bool, uint64_t> OfflineDatabase::putInternal(const Resource& resource, const Response& response, bool evict_) {
Expand Down Expand Up @@ -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 "
Expand Down Expand Up @@ -329,7 +327,6 @@ bool OfflineDatabase::putResource(const Resource& resource,

updateQuery.run();
if (updateQuery.changes() != 0) {
transaction.commit();
return false;
}

Expand All @@ -356,7 +353,6 @@ bool OfflineDatabase::putResource(const Resource& resource,
}

insertQuery.run();
transaction.commit();

return true;
}
Expand Down Expand Up @@ -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 "
Expand Down Expand Up @@ -526,7 +518,6 @@ bool OfflineDatabase::putTile(const Resource::TileData& tile,

updateQuery.run();
if (updateQuery.changes() != 0) {
transaction.commit();
return false;
}

Expand Down Expand Up @@ -556,7 +547,6 @@ bool OfflineDatabase::putTile(const Resource::TileData& tile,
}

insertQuery.run();
transaction.commit();

return true;
}
Expand Down

0 comments on commit 3f22443

Please sign in to comment.