summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-11-08 14:42:29 +0200
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-11-12 17:24:50 +0200
commit615e095ed6d40771a1e38d5078cf3d821b0d7217 (patch)
treeedd9ebe52335060bafff1131edc2797c0c3106c7 /platform
parentc1b2e8c9a013677ee795321ba74427551e6ecf2e (diff)
downloadqtlocation-mapboxgl-615e095ed6d40771a1e38d5078cf3d821b0d7217.tar.gz
[core] OfflineDatabase pack API
- introduce `OfflineDatabase::pack()` standing for incremental vacuum - make pack optional at offline region deletion - update `OfflineDatabase.DeleteRegion` test accordingly to the items above
Diffstat (limited to 'platform')
-rw-r--r--platform/default/include/mbgl/storage/offline_database.hpp3
-rw-r--r--platform/default/src/mbgl/storage/offline_database.cpp16
2 files changed, 15 insertions, 4 deletions
diff --git a/platform/default/include/mbgl/storage/offline_database.hpp b/platform/default/include/mbgl/storage/offline_database.hpp
index f097cd5440..ac997bf6ad 100644
--- a/platform/default/include/mbgl/storage/offline_database.hpp
+++ b/platform/default/include/mbgl/storage/offline_database.hpp
@@ -74,7 +74,7 @@ public:
expected<OfflineRegionMetadata, std::exception_ptr>
updateMetadata(const int64_t regionID, const OfflineRegionMetadata&);
- std::exception_ptr deleteRegion(OfflineRegion&&);
+ std::exception_ptr deleteRegion(OfflineRegion&&, bool pack = true);
std::exception_ptr invalidateRegion(int64_t regionID);
// Return value is (response, stored size)
@@ -93,6 +93,7 @@ public:
uint64_t getOfflineMapboxTileCount();
bool exceedsOfflineMapboxTileCountLimit(const Resource&);
void markUsedResources(int64_t regionID, const std::list<Resource>&);
+ std::exception_ptr pack();
private:
void initialize();
diff --git a/platform/default/src/mbgl/storage/offline_database.cpp b/platform/default/src/mbgl/storage/offline_database.cpp
index 4f813e906d..fef524ce57 100644
--- a/platform/default/src/mbgl/storage/offline_database.cpp
+++ b/platform/default/src/mbgl/storage/offline_database.cpp
@@ -197,6 +197,7 @@ void OfflineDatabase::migrateToVersion6() {
}
void OfflineDatabase::vacuum() {
+ assert(db);
if (getPragma<int64_t>("PRAGMA auto_vacuum") != 2 /*INCREMENTAL*/) {
db->exec("PRAGMA auto_vacuum = INCREMENTAL");
db->exec("VACUUM");
@@ -883,7 +884,7 @@ OfflineDatabase::updateMetadata(const int64_t regionID, const OfflineRegionMetad
return unexpected<std::exception_ptr>(std::current_exception());
}
-std::exception_ptr OfflineDatabase::deleteRegion(OfflineRegion&& region) try {
+std::exception_ptr OfflineDatabase::deleteRegion(OfflineRegion&& region, bool pack) try {
{
mapbox::sqlite::Query query{ getStatement("DELETE FROM regions WHERE id = ?") };
query.bind(1, region.getID());
@@ -892,10 +893,10 @@ std::exception_ptr OfflineDatabase::deleteRegion(OfflineRegion&& region) try {
evict(0);
assert(db);
- vacuum();
+ if (pack) vacuum();
// Ensure that the cached offlineTileCount value is recalculated.
- offlineMapboxTileCount = {};
+ offlineMapboxTileCount = nullopt;
return nullptr;
} catch (...) {
handleError("delete region");
@@ -1303,6 +1304,15 @@ void OfflineDatabase::markUsedResources(int64_t regionID, const std::list<Resour
handleError("mark resources as used");
}
+std::exception_ptr OfflineDatabase::pack() try {
+ if (!db) initialize();
+ vacuum();
+ return nullptr;
+} catch (...) {
+ handleError("pack storage");
+ return std::current_exception();
+}
+
std::exception_ptr OfflineDatabase::resetDatabase() try {
removeExisting();
initialize();