fix(places): a rebuild writes its files before removing stale tiles, and keeps the build date when nothing changed

Co-authored-by: Manjunath Paparaju <[email protected]>
This commit is contained in:
Sameh KhamisandManjunath Paparaju committed 2026-11-18 22:34:59 -08:00
1 parent 30ec362c13
commit a2c86c0fed
4 files changed
+55 -4

No files matched your search

@@ -36,6 +36,7 @@ places without an English label.
The build runs one query at a time with pauses and honours the service's
Retry-After; it takes about ten minutes. It fails if a short list of
well-known cities is missing from the result, or a known grouping gets in.
`meta.built` keeps its earlier date when the rows are unchanged.
**Limits:** populations are whatever Wikidata states and differ in date and
definition between places (city proper, municipality, urban district). Some
+11
View File
@@ -8,6 +8,7 @@ import { createHash } from 'node:crypto';
import { readdir, readFile } from 'node:fs/promises';
import test from 'node:test';
import {
keepBuiltIfUnchanged,
placeTileFiles,
tileKey,
withoutCities,
@@ -103,3 +104,13 @@ test('twins are found where longitude cells narrow, and across 180°', () => {
['Q1', 'Q3'],
);
});
test('a rebuild of unchanged rows keeps the earlier build stamp', () => {
const earlier = `${JSON.stringify({ meta: { built: '2026-01-01T00:00:00.000Z', count: 2 }, rows: [1, 2] })}\n`;
const same = `${JSON.stringify({ meta: { built: '2026-11-18T00:00:00.000Z', count: 2 }, rows: [1, 2] })}\n`;
const changed = `${JSON.stringify({ meta: { built: '2026-11-18T00:00:00.000Z', count: 3 }, rows: [1, 2, 3] })}\n`;
assert.equal(keepBuiltIfUnchanged(same, earlier), earlier);
assert.equal(keepBuiltIfUnchanged(changed, earlier), changed);
assert.equal(keepBuiltIfUnchanged(same, undefined), same);
assert.equal(keepBuiltIfUnchanged(same, 'not json'), same);
});