From ea63541ad1b3fb6791d56f59e9d7189a5948df9c Mon Sep 17 00:00:00 2001 From: "Thiago Marcos P. Santos" Date: Tue, 18 Jun 2019 18:51:05 +0300 Subject: [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. --- platform/default/src/mbgl/storage/offline_database.cpp | 18 ++++++++++-------- 1 file 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( -- cgit v1.2.1