mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 09:42:21 +00:00
test(places): pin the pack build-date rule and a nearer village beating a namesake inside a wide search
Co-authored-by: Manjunath Paparaju <[email protected]>
This commit is contained in:
1 parent
75e345aa07
commit
50824c9a65
4 files changed
+66
-19
No files matched your search
@@ -40,6 +40,7 @@ import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import {
|
||||
keepBuiltIfUnchanged,
|
||||
keepPackBuiltIfUnchanged,
|
||||
placeTileFiles,
|
||||
withoutCities,
|
||||
withoutNearTwins,
|
||||
@@ -505,25 +506,11 @@ 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.
|
||||
// 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')),
|
||||
),
|
||||
);
|
||||
const earlier = new Map();
|
||||
for (const name of await readdir(outDir))
|
||||
if (/^-?\d+_-?\d+\.json$|^index\.json$|^files\.js$/.test(name))
|
||||
earlier.set(name, await readFile(path.join(outDir, name), 'utf8'));
|
||||
keepPackBuiltIfUnchanged(files, earlier);
|
||||
for (const [name, text] of files)
|
||||
await writeFile(path.join(outDir, name), text);
|
||||
for (const name of await readdir(outDir))
|
||||
|
||||
@@ -114,6 +114,26 @@ export function keepBuiltIfUnchanged(text, earlier) {
|
||||
return `${JSON.stringify({ ...after, meta: { ...after.meta, built: before.meta.built } })}\n`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Keeps the earlier build's `meta.built` in the places pack's index when the
|
||||
* rebuild changed nothing: every tile and `files.js` the same text, no tile
|
||||
* of the earlier build left out, and nothing else in the index changed. The
|
||||
* index holds only row counts, so it alone cannot tell.
|
||||
* @param {Map<string, string>} files The new pack, as placeTileFiles gives it; its index is replaced in place.
|
||||
* @param {Map<string, string>} earlier The pack's files on disk now, by name.
|
||||
*/
|
||||
export function keepPackBuiltIfUnchanged(files, earlier) {
|
||||
for (const name of earlier.keys())
|
||||
if (name !== 'index.json' && !files.has(name)) return files;
|
||||
for (const [name, text] of files)
|
||||
if (name !== 'index.json' && earlier.get(name) !== text) return files;
|
||||
files.set(
|
||||
'index.json',
|
||||
keepBuiltIfUnchanged(files.get('index.json'), earlier.get('index.json')),
|
||||
);
|
||||
return files;
|
||||
}
|
||||
|
||||
const kmBetween = (a, b) =>
|
||||
greatCircleKm({ lat: a[1], lon: a[2] }, { lat: b[1], lon: b[2] });
|
||||
|
||||
|
||||
Reference in new issue
Block a user