summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <tmpsantos@gmail.com>2019-05-16 16:29:12 +0300
committerThiago Marcos P. Santos <tmpsantos@gmail.com>2019-05-21 01:04:01 +0300
commit1def782cf23736f06d0d6809ea0881f7913796b2 (patch)
tree376ed267234e4b04043738f8530ab1f6f2197b5e
parent2a3a1c7bb36410c6037f1d8da46fa68733efbe42 (diff)
downloadqtlocation-mapboxgl-1def782cf23736f06d0d6809ea0881f7913796b2.tar.gz
[core] Add API for invalidating tiles
Add new APIs for invalidating tiles, effectively forcing Mapbox GL Native to check with the servers if the tiles are valid before using them. This is more efficient then deleting tiles, because in case of valid tiles, they won't get downloaded. Fixes #4376.
-rw-r--r--platform/default/include/mbgl/storage/offline_database.hpp8
-rw-r--r--platform/default/src/mbgl/storage/offline_database.cpp41
2 files changed, 49 insertions, 0 deletions
diff --git a/platform/default/include/mbgl/storage/offline_database.hpp b/platform/default/include/mbgl/storage/offline_database.hpp
index 3ba15d5813..3de829e635 100644
--- a/platform/default/include/mbgl/storage/offline_database.hpp
+++ b/platform/default/include/mbgl/storage/offline_database.hpp
@@ -51,6 +51,13 @@ public:
// Return value is (inserted, stored size)
std::pair<bool, uint64_t> put(const Resource&, const Response&);
+ // Force Mapbox GL Native to revalidate tiles stored in the ambient
+ // cache with the tile server before using them, making sure they
+ // are the latest version. This is more efficient than cleaning the
+ // cache because if the tile is considered valid after the server
+ // lookup, it will not get downloaded again.
+ std::exception_ptr invalidateTileCache();
+
expected<OfflineRegions, std::exception_ptr> listRegions();
expected<OfflineRegion, std::exception_ptr> createRegion(const OfflineRegionDefinition&,
@@ -63,6 +70,7 @@ public:
updateMetadata(const int64_t regionID, const OfflineRegionMetadata&);
std::exception_ptr deleteRegion(OfflineRegion&&);
+ std::exception_ptr invalidateRegion(int64_t regionID);
// Return value is (response, stored size)
optional<std::pair<Response, uint64_t>> getRegionResource(int64_t regionID, const Resource&);
diff --git a/platform/default/src/mbgl/storage/offline_database.cpp b/platform/default/src/mbgl/storage/offline_database.cpp
index 1639c4484c..0b3bcc049f 100644
--- a/platform/default/src/mbgl/storage/offline_database.cpp
+++ b/platform/default/src/mbgl/storage/offline_database.cpp
@@ -606,6 +606,47 @@ bool OfflineDatabase::putTile(const Resource::TileData& tile,
return true;
}
+std::exception_ptr OfflineDatabase::invalidateTileCache() try {
+ // clang-format off
+ mapbox::sqlite::Query query{ getStatement(
+ "UPDATE tiles "
+ "SET expires = 0, must_revalidate = 1 "
+ "WHERE id NOT IN ("
+ " SELECT tile_id FROM region_tiles"
+ ")"
+ ) };
+ // clang-format on
+
+ query.run();
+ return nullptr;
+} catch (const mapbox::sqlite::Exception& ex) {
+ handleError(ex, "invalidate tile cache");
+ return std::current_exception();
+}
+
+std::exception_ptr OfflineDatabase::invalidateRegion(int64_t regionID) try {
+ {
+ // clang-format off
+ mapbox::sqlite::Query query{ getStatement(
+ "UPDATE tiles "
+ "SET expires = 0, must_revalidate = 1 "
+ "WHERE id IN ("
+ " SELECT tile_id FROM region_tiles WHERE region_id = ?"
+ ")"
+ ) };
+ // clang-format on
+
+ query.bind(1, regionID);
+ query.run();
+ }
+
+ assert(db);
+ return nullptr;
+} catch (const mapbox::sqlite::Exception& ex) {
+ handleError(ex, "invalidate region");
+ return std::current_exception();
+}
+
expected<OfflineRegions, std::exception_ptr> OfflineDatabase::listRegions() try {
mapbox::sqlite::Query query{ getStatement("SELECT id, definition, description FROM regions") };
OfflineRegions result;