diff options
author | Thiago Marcos P. Santos <tmpsantos@gmail.com> | 2019-06-14 16:53:09 +0300 |
---|---|---|
committer | Thiago Marcos P. Santos <tmpsantos@gmail.com> | 2019-06-18 16:26:51 +0300 |
commit | 78eeffe1717a37a91e6c59681421a20c52a4d003 (patch) | |
tree | b81e50aba9dcf531a96c9f5a25d1f723b3f72cee /platform/default/src/mbgl/storage/offline_database.cpp | |
parent | 59e7b9a8780e282cf90ede7ae8e3b1affe1e684e (diff) | |
download | qtlocation-mapboxgl-78eeffe1717a37a91e6c59681421a20c52a4d003.tar.gz |
[core] Clear/Invalidate should also work on non-tile resources
These methods were only affecting tiles, but they should really
work on every resource like style, glyphs, etc.
Diffstat (limited to 'platform/default/src/mbgl/storage/offline_database.cpp')
-rw-r--r-- | platform/default/src/mbgl/storage/offline_database.cpp | 59 |
1 files changed, 48 insertions, 11 deletions
diff --git a/platform/default/src/mbgl/storage/offline_database.cpp b/platform/default/src/mbgl/storage/offline_database.cpp index ab04cde5ed..7caa013f9f 100644 --- a/platform/default/src/mbgl/storage/offline_database.cpp +++ b/platform/default/src/mbgl/storage/offline_database.cpp @@ -604,9 +604,9 @@ bool OfflineDatabase::putTile(const Resource::TileData& tile, return true; } -std::exception_ptr OfflineDatabase::invalidateTileCache() try { +std::exception_ptr OfflineDatabase::invalidateAmbientCache() try { // clang-format off - mapbox::sqlite::Query query{ getStatement( + mapbox::sqlite::Query tileQuery{ getStatement( "UPDATE tiles " "SET expires = 0, must_revalidate = 1 " "WHERE id NOT IN (" @@ -615,16 +615,29 @@ std::exception_ptr OfflineDatabase::invalidateTileCache() try { ) }; // clang-format on - query.run(); + tileQuery.run(); + + // clang-format off + mapbox::sqlite::Query resourceQuery{ getStatement( + "UPDATE resources " + "SET expires = 0, must_revalidate = 1 " + "WHERE id NOT IN (" + " SELECT resource_id FROM region_resources" + ")" + ) }; + // clang-format on + + resourceQuery.run(); + return nullptr; } catch (const mapbox::sqlite::Exception& ex) { - handleError(ex, "invalidate tile cache"); + handleError(ex, "invalidate ambient cache"); return std::current_exception(); } -std::exception_ptr OfflineDatabase::clearTileCache() try { +std::exception_ptr OfflineDatabase::clearAmbientCache() try { // clang-format off - mapbox::sqlite::Query query{ getStatement( + mapbox::sqlite::Query tileQuery{ getStatement( "DELETE FROM tiles " "WHERE id NOT IN (" " SELECT tile_id FROM region_tiles" @@ -632,20 +645,31 @@ std::exception_ptr OfflineDatabase::clearTileCache() try { ) }; // clang-format on - query.run(); + tileQuery.run(); + + // clang-format off + mapbox::sqlite::Query resourceQuery{ getStatement( + "DELETE FROM resources " + "WHERE id NOT IN (" + " SELECT resource_id FROM region_resources" + ")" + ) }; + // clang-format on + + resourceQuery.run(); db->exec("VACUUM"); return nullptr; } catch (const mapbox::sqlite::Exception& ex) { - handleError(ex, "clear tile cache"); + handleError(ex, "clear ambient cache"); return std::current_exception(); } std::exception_ptr OfflineDatabase::invalidateRegion(int64_t regionID) try { { // clang-format off - mapbox::sqlite::Query query{ getStatement( + mapbox::sqlite::Query tileQuery{ getStatement( "UPDATE tiles " "SET expires = 0, must_revalidate = 1 " "WHERE id IN (" @@ -654,8 +678,21 @@ std::exception_ptr OfflineDatabase::invalidateRegion(int64_t regionID) try { ) }; // clang-format on - query.bind(1, regionID); - query.run(); + tileQuery.bind(1, regionID); + tileQuery.run(); + + // clang-format off + mapbox::sqlite::Query resourceQuery{ getStatement( + "UPDATE resources " + "SET expires = 0, must_revalidate = 1 " + "WHERE id IN (" + " SELECT resource_id FROM region_resources WHERE region_id = ?" + ")" + ) }; + // clang-format on + + resourceQuery.bind(1, regionID); + resourceQuery.run(); } assert(db); |