diff options
author | Eric Wolfe <eric.r.wolfe@gmail.com> | 2017-01-18 18:43:24 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-18 18:43:24 -0800 |
commit | a2ceeb4a5b7a8db4bbd852c5e51085d9220a5c3d (patch) | |
tree | 3fd1e0fc959eed6e9d8737d18fdf531f41fe16f6 | |
parent | feb4da4a24e5d8d555884c424b061521b0aff412 (diff) | |
download | qtlocation-mapboxgl-a2ceeb4a5b7a8db4bbd852c5e51085d9220a5c3d.tar.gz |
[core] Evict cached resources and tiles equally by access time (#7770)
-rw-r--r-- | platform/default/mbgl/storage/offline_database.cpp | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/platform/default/mbgl/storage/offline_database.cpp b/platform/default/mbgl/storage/offline_database.cpp index 73364b042f..49359dbd39 100644 --- a/platform/default/mbgl/storage/offline_database.cpp +++ b/platform/default/mbgl/storage/offline_database.cpp @@ -793,6 +793,31 @@ bool OfflineDatabase::evict(uint64_t neededFreeSize) { // size, and because pages can get fragmented on the database. while (usedSize() + neededFreeSize + pageSize > maximumCacheSize) { // clang-format off + Statement accessedStmt = getStatement( + "SELECT max(accessed) " + "FROM ( " + " SELECT accessed " + " FROM resources " + " LEFT JOIN region_resources " + " ON resource_id = resources.id " + " WHERE resource_id IS NULL " + " UNION ALL " + " SELECT accessed " + " FROM tiles " + " LEFT JOIN region_tiles " + " ON tile_id = tiles.id " + " WHERE tile_id IS NULL " + " ORDER BY accessed ASC LIMIT ?1 " + ") " + ); + accessedStmt->bind(1, 50); + // clang-format on + if (!accessedStmt->run()) { + return false; + } + Timestamp accessed = accessedStmt->get<Timestamp>(0); + + // clang-format off Statement stmt1 = getStatement( "DELETE FROM resources " "WHERE id IN ( " @@ -800,10 +825,10 @@ bool OfflineDatabase::evict(uint64_t neededFreeSize) { " LEFT JOIN region_resources " " ON resource_id = resources.id " " WHERE resource_id IS NULL " - " ORDER BY accessed ASC LIMIT ?1 " + " AND accessed <= ?1 " ") "); // clang-format on - stmt1->bind(1, 50); + stmt1->bind(1, accessed); stmt1->run(); uint64_t changes1 = db->changes(); @@ -815,10 +840,10 @@ bool OfflineDatabase::evict(uint64_t neededFreeSize) { " LEFT JOIN region_tiles " " ON tile_id = tiles.id " " WHERE tile_id IS NULL " - " ORDER BY accessed ASC LIMIT ?1 " + " AND accessed <= ?1 " ") "); // clang-format on - stmt2->bind(1, 50); + stmt2->bind(1, accessed); stmt2->run(); uint64_t changes2 = db->changes(); |