summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <tmpsantos@gmail.com>2019-06-18 18:51:05 +0300
committerThiago Marcos P. Santos <tmpsantos@gmail.com>2019-06-19 17:19:10 +0300
commitea63541ad1b3fb6791d56f59e9d7189a5948df9c (patch)
treebcf85742d4b17b0595654485c81a5446d8f435cf
parentbd481b1d60132c1b7f8ab1ebd8e363802907f9d5 (diff)
downloadqtlocation-mapboxgl-ea63541ad1b3fb6791d56f59e9d7189a5948df9c.tar.gz
[core] Fix offline regions reporting the wrong number of tiles
- The SQL query used for checking if the tile was already in the cache was wrong. - Tiles being refereed by two or more regions were not always counted as one. Fixes #13437.
-rw-r--r--platform/default/src/mbgl/storage/offline_database.cpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/platform/default/src/mbgl/storage/offline_database.cpp b/platform/default/src/mbgl/storage/offline_database.cpp
index 24ad3e8432..d85b560d5a 100644
--- a/platform/default/src/mbgl/storage/offline_database.cpp
+++ b/platform/default/src/mbgl/storage/offline_database.cpp
@@ -964,13 +964,13 @@ void OfflineDatabase::putRegionResources(int64_t regionID,
}
uint64_t OfflineDatabase::putRegionResourceInternal(int64_t regionID, const Resource& resource, const Response& response) {
- if (exceedsOfflineMapboxTileCountLimit(resource)) {
- throw MapboxTileLimitExceededException();
- }
-
uint64_t size = putInternal(resource, response, false).second;
bool previouslyUnused = markUsed(regionID, resource);
+ if (previouslyUnused && exceedsOfflineMapboxTileCountLimit(resource)) {
+ throw MapboxTileLimitExceededException();
+ }
+
if (offlineMapboxTileCount
&& resource.kind == Resource::Kind::Tile
&& util::mapbox::isMapboxURL(resource.url)
@@ -1004,15 +1004,14 @@ bool OfflineDatabase::markUsed(int64_t regionID, const Resource& resource) {
insertQuery.bind(6, tile.z);
insertQuery.run();
- if (insertQuery.changes() == 0) {
- return false;
- }
+ bool notOnThisRegion = insertQuery.changes() != 0;
// clang-format off
mapbox::sqlite::Query selectQuery{ getStatement(
"SELECT region_id "
"FROM region_tiles, tiles "
"WHERE region_id != ?1 "
+ " AND tile_id = id "
" AND url_template = ?2 "
" AND pixel_ratio = ?3 "
" AND x = ?4 "
@@ -1027,7 +1026,10 @@ bool OfflineDatabase::markUsed(int64_t regionID, const Resource& resource) {
selectQuery.bind(4, tile.x);
selectQuery.bind(5, tile.y);
selectQuery.bind(6, tile.z);
- return !selectQuery.run();
+
+ bool notOnOtherRegion = !selectQuery.run();
+
+ return notOnThisRegion && notOnOtherRegion;
} else {
// clang-format off
mapbox::sqlite::Query insertQuery{ getStatement(