fix(street-level): bound the tile proxy's disk cache and keep tiles' age

From the IC8 review of #768 (P2s), each with a test that fails before:

- A tile read from disk keeps its real age in memory, and the trim rewrite
  keeps the file's mtime, so nothing is served past the 24 h TTL.
- The disk cache is swept in the background at most every 15 min: expired
  tiles go, then the oldest past 1 GiB. Coverage zooms the app never
  requests (z6-10) are refused with a 400, and layer names are matched as
  own keys only.
- The tests run against a temporary cache directory (a test seam) instead
  of writing into and deleting from the developer's real .gev-cache.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Said TurkseverandClaude Opus 5.5 committed 2026-10-05 15:55:18 +01:00
1 parent 539d514adb
commit 0a3dc4c4ae
4 files changed
+311 -54

No files matched your search

+11 -2
View File
@@ -6,12 +6,13 @@ export const MAPILLARY_TILE_HOST = 'https://tiles.mapillary.com/maps/vtp';
/** Public tile layer names this proxy exposes, mapped to Mapillary's ids. */
export const TILE_LAYERS = Object.freeze({
// Overview points (z0–5), sequences (z6–14) and image points (z14 only).
// The app asks for overview z0–5 and sequences z11–14 only (see
// src/layers/streetLevel/tileMath.js); region-sized z6–10 tiles are refused.
// The z14 `image` point layer is ~98% of a 10 MB tile and unused here:
// image positions come from the graph API per sequence. Dropped in transit.
coverage: Object.freeze({
upstream: 'mly1_public',
minZoom: 0,
maxZoom: 14,
zoomRanges: Object.freeze([Object.freeze([0, 5]), Object.freeze([11, 14])]),
dropLayers: Object.freeze(['image']),
}),
});
@@ -31,6 +32,14 @@ export const TILE_DISK_DIR = path.join(MAPILLARY_CACHE_DIR, 'tiles');
*/
export const TILE_DISK_TTL_MS = 24 * 60 * 60 * 1000;
/**
* Disk cache bound. A tile write starts a background sweep at most this often:
* it deletes files past TILE_DISK_TTL_MS, then the oldest files until the
* cache fits in TILE_DISK_MAX_BYTES (thousands of trimmed street-level tiles).
*/
export const TILE_DISK_SWEEP_INTERVAL_MS = 15 * 60 * 1000;
export const TILE_DISK_MAX_BYTES = 1024 * 1024 * 1024;
/** A z14 image tile over a dense city is ~11 MB; anything past this is wrong. */
export const TILE_MAX_BYTES = 48 * 1024 * 1024;