fix(places): keep the places index's build date only when every tile is unchanged; say the 500 km cap is for wide lookups

Co-authored-by: Manjunath Paparaju <[email protected]>
This commit is contained in:
Sameh KhamisandManjunath Paparaju committed 2026-11-18 22:44:12 -08:00
1 parent ecb7e7cd68
commit d2797dbad2
7 files changed
+37 -19

No files matched your search

+3 -3
View File
@@ -1,4 +1,4 @@
- "Villages near" a name picks the place of that name in view over a far
bigger namesake, a view of the whole globe reads only the place tiles
around its centre, and rebuilding the places pack never leaves it half
removed (manjunath22466, samehkhamis, #1838).
bigger namesake, a place lookup reads the detail tiles within 500 km at
most, and rebuilding the places pack never leaves it half removed
(manjunath22466, samehkhamis, #1838).
+2 -2
View File
@@ -8254,8 +8254,8 @@ the city is listed. A place named in "villages near …" is the nearest of
that name within 150 km of the view, small places included, so a village in
view comes before a bigger namesake far away; with none near, the largest
city of the name. Small places are looked for within 500 km at most, so a
view zoomed out to the whole globe reads only the detail tiles around its
centre. At most 64 detail tiles are kept in memory, the least
lookup asked for a wider radius reads only the detail tiles around its
centre (the search box asks for 150 km at most). At most 64 detail tiles are kept in memory, the least
recently used dropped first.
### Place-search providers
+18 -4
View File
@@ -505,11 +505,25 @@ if (tilesMode) {
// The new files are all written before tiles from an earlier build that
// this one has no rows for go, so a build that stops part way never leaves
// an index naming a removed tile.
const indexFile = path.join(outDir, 'index.json');
files.set(
'index.json',
keepBuiltIfUnchanged(files.get('index.json'), await readIfThere(indexFile)),
// The index holds only row counts, so its build date is kept only when
// every tile is unchanged too and no earlier tile is left over.
const earlierTiles = (await readdir(outDir)).filter((name) =>
/^-?\d+_-?\d+\.json$/.test(name),
);
let tilesUnchanged = earlierTiles.every((name) => files.has(name));
for (const [name, text] of files) {
if (!tilesUnchanged) break;
if (name === 'index.json') continue;
tilesUnchanged = (await readIfThere(path.join(outDir, name))) === text;
}
if (tilesUnchanged)
files.set(
'index.json',
keepBuiltIfUnchanged(
files.get('index.json'),
await readIfThere(path.join(outDir, 'index.json')),
),
);
for (const [name, text] of files)
await writeFile(path.join(outDir, name), text);
for (const name of await readdir(outDir))
+3 -1
View File
@@ -92,7 +92,9 @@ export function placeTileFiles(rows, meta) {
/**
* A pack file's new text, keeping the earlier build's `meta.built` when
* nothing else in the file changed, so rebuilding unchanged data leaves the
* file as it was.
* file as it was. A file that does not hold all of its pack's data (the
* places index) is passed through this only when the rest of the pack is
* unchanged too.
* @param {string} text The new file, JSON with a `meta.built` stamp.
* @param {string | undefined} earlier The file as it is now, if there is one.
*/
@@ -20,8 +20,9 @@ entry in the index.
**Loading:** nothing here loads with the app. A lookup reads `files.js` and
the index once, then only the tiles its search box touches (one for a short
radius well inside a tile, more near tile edges and for wider searches),
once each. The search box reaches 500 km at most (`PLACE_TILE_KM`), so a
view of the whole globe reads only the tiles around its centre: at most one
once each. A lookup reaches 500 km at most (`PLACE_TILE_KM`; the search box
asks for 150 km at most), so one asked for a wider radius reads only the
tiles around its centre: at most one
tile past the centre's own on each side, a few more columns toward the
poles, and never all 732. Cities still count to the full radius. At most
64 tiles are kept in memory, the least recently used
@@ -48,8 +49,8 @@ It writes only to this folder (tiles, `index.json`, `files.js`, through
`scripts/wikidataPlaceTiles.mjs`) and leaves `../wikidata_cities` alone. It
runs one query at a time with pauses and takes a long while. The new files
are all written before tiles that the new build has no rows for are
removed, and `meta.built` keeps its earlier date when nothing else in
`index.json` changed.
removed, and `meta.built` keeps its earlier date when no tile and
nothing else in `index.json` changed.
**Reproducibility:** the step from rows to files is checked offline:
`src/tooling/wikidataPlaceTiles.test.mjs` sorts the shipped rows as the
+5 -4
View File
@@ -219,10 +219,11 @@ const TILE_DEG = 5;
const MAX_TILES = 64;
/**
* How far out small places are looked for, in km. 500 km is under the 556 km
* that 5 degrees of latitude span, so the search box reaches at most one tile
* past the point's own on each side: 3 rows, and 3 columns at the equator
* (more toward the poles, where tiles narrow). A wider view, out to the whole
* globe, still reads only those tiles; cities count to its full radius.
* that 5 degrees of latitude span, so a lookup's tile box reaches at most one
* tile past the point's own on each side: 3 rows, and 3 columns at the
* equator (more toward the poles, where tiles narrow). A lookup asked for a
* wider radius, up to the whole globe, still reads only those tiles; cities
* count to its full radius.
*/
export const PLACE_TILE_KM = 500;
const NAMED = /\p{L}/u;
+1 -1
View File
@@ -282,7 +282,7 @@ test('a tile that cannot be read leaves the other places and the cities', async
assert.ok(near.some((place) => place.longitude > -95));
});
test('a view of the whole globe reads only the tiles near its centre', async () => {
test('a lookup asked for the whole globe reads only the tiles near its centre', async () => {
const { placesNear, PLACE_TILE_KM } =
await import('./wikidataCities.js?globe');
const fetched = [];