fix(terrain): refresh cache recency when resolving warm batches

This commit is contained in:
Rudy Celekli committed 2026-10-14 20:11:49 -04:00
1 parent 0265ad4c19
commit 9f56e9df98
4 files changed
+31 -1

No files matched your search

@@ -0,0 +1,24 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { createTerrainHeights } from './terrainHeights.js';
test('warm batch consumers retain their terrain cells ahead of unused cells', async () => {
let calls = 0;
const terrain = createTerrainHeights({
maxCacheEntries: 2,
source: {
async getHeights(points) {
calls++;
return points.map((p) => ({ ellipsoid: 100 + p.lon }));
},
},
});
const p = (lon) => ({ lat: 0, lon });
await terrain.resolveEllipsoidalGround([p(1)]);
await terrain.resolveEllipsoidalGround([p(2)]);
await terrain.resolveEllipsoidalGround([p(1)]);
assert.equal(calls, 2);
await terrain.resolveEllipsoidalGround([p(3)]);
assert.equal(terrain.cachedEllipsoidalGround(0, 1), 101);
assert.equal(terrain.cachedEllipsoidalGround(0, 2), null);
assert.equal(calls, 3);
});
+1 -1
View File
@@ -273,7 +273,7 @@ export function createTerrainHeights({
const seenKeys = new Set();
const now = Date.now();
for (const item of work) {
const entry = cache.get(item.key);
const entry = cacheTouch(item.key);
const fallbackCooling =
entry?.source === 'geoid-fallback' &&
Number.isFinite(entry.retryAt) &&