map | list : speed & nav
This commit is contained in:
parent
02700a15f1
commit
1188a00fcc
12
dist/gpkg-reader.js
vendored
12
dist/gpkg-reader.js
vendored
File diff suppressed because one or more lines are too long
8
dist/wrapper.js
vendored
8
dist/wrapper.js
vendored
File diff suppressed because one or more lines are too long
@ -404,14 +404,10 @@ export async function getBoundaryFromGpkg(
|
||||
}
|
||||
|
||||
const countryCode = gadmId.split('.')[0];
|
||||
console.log(`----------------- [gpkg-reader] Checking local FS cache for ${cacheKey} (Country: ${countryCode})`);
|
||||
|
||||
for (const dir of uniqueCacheDirs) {
|
||||
const cacheFile = join(dir, countryCode, `${cacheKey}.json`);
|
||||
console.log(`[gpkg-reader] Checking exact cache file: ${cacheFile}`);
|
||||
if (existsSync(cacheFile)) {
|
||||
try {
|
||||
console.log(`[gpkg-reader] HIT exact cache file: ${cacheFile}`);
|
||||
return JSON.parse(readFileSync(cacheFile, 'utf-8')) as BoundaryResult;
|
||||
} catch (e) {
|
||||
console.warn(`[gpkg-reader] Failed to read cache from ${cacheFile}:`, e);
|
||||
@ -422,16 +418,12 @@ export async function getBoundaryFromGpkg(
|
||||
|
||||
// fallback old flat structure
|
||||
const oldCacheFile = join(dir, `${cacheKey}.json`);
|
||||
console.log(`[gpkg-reader] Checking flat cache file: ${oldCacheFile}`);
|
||||
if (existsSync(oldCacheFile)) {
|
||||
try {
|
||||
console.log(`[gpkg-reader] HIT flat cache file: ${oldCacheFile}`);
|
||||
return JSON.parse(readFileSync(oldCacheFile, 'utf-8')) as BoundaryResult;
|
||||
} catch (e) {
|
||||
console.warn(`[gpkg-reader] Failed to read backup cache from ${oldCacheFile}:`, e);
|
||||
}
|
||||
} else {
|
||||
console.log(`[gpkg-reader] MISS flat cache file: ${oldCacheFile}`);
|
||||
}
|
||||
}
|
||||
|
||||
@ -755,7 +747,7 @@ export async function getHierarchyByPointFromCache(lat: number, lon: number, iso
|
||||
}
|
||||
if (process.env.GADM_CACHE) possibleCacheDirs.push(process.env.GADM_CACHE);
|
||||
possibleCacheDirs.push(resolve(process.cwd(), 'cache/gadm'));
|
||||
possibleCacheDirs.push(resolve(__dirname, '../cache/gadm'));
|
||||
//possibleCacheDirs.push(resolve(__dirname, '../cache/gadm'));
|
||||
const uniqueCacheDirs = [...new Set(possibleCacheDirs)];
|
||||
// Check downwards from most detailed to least (country base).
|
||||
for (let level = 5; level >= 0; level--) {
|
||||
|
||||
@ -171,8 +171,6 @@ export async function getBoundary(
|
||||
resolution: number = 3
|
||||
): Promise<GeoJSONCollection | { error: string }> {
|
||||
|
||||
console.log('getBoundary', gadmId, contentLevel, enrichOptions, resolution, cache);
|
||||
|
||||
const enrichKeySuffix = enrichOptions ? '_enriched' : '';
|
||||
const keySuffix = `${contentLevel ?? 'auto'}_${gadmId}${enrichKeySuffix}`;
|
||||
const key = getCacheKey(`boundary`, keySuffix);
|
||||
@ -180,7 +178,6 @@ export async function getBoundary(
|
||||
// 1. Check if we already have the EXACT requested state cached
|
||||
const cached = await readCache<GeoJSONCollection>(key, cache);
|
||||
if (cached) {
|
||||
console.log('getBoundary cache hit', key);
|
||||
return cached;
|
||||
}
|
||||
|
||||
@ -190,7 +187,7 @@ export async function getBoundary(
|
||||
// First try the far superior SQLite GeoPackage
|
||||
const gpkgRes = await getBoundaryFromGpkg(gadmId, contentLevel, cache, resolution);
|
||||
if (gpkgRes) {
|
||||
console.log('getBoundary gpkgRes', gpkgRes);
|
||||
|
||||
baseCollection = gpkgRes;
|
||||
} else {
|
||||
// Fallback exactly as before to Parquet mode
|
||||
@ -198,10 +195,8 @@ export async function getBoundary(
|
||||
const baseKey = getCacheKey(`boundary_${contentLevel ?? 'auto'}`, gadmId);
|
||||
const baseCached = await readCache<GeoJSONCollection>(baseKey, cache);
|
||||
if (baseCached) {
|
||||
console.log('getBoundary baseCached', baseCached);
|
||||
baseCollection = baseCached;
|
||||
} else {
|
||||
console.log('getBoundary baseCached miss', baseCached);
|
||||
try {
|
||||
const gdf = await getItems({ admin: [gadmId], contentLevel, cache });
|
||||
if (gdf.features.length === 0) {
|
||||
@ -222,10 +217,8 @@ export async function getBoundary(
|
||||
(f: any) => f.properties?.ghsPopulation !== undefined
|
||||
);
|
||||
if (enrichOptions && !alreadyEnriched && baseCollection && baseCollection.features) {
|
||||
console.log('getBoundary enrichOptions', enrichOptions);
|
||||
// Deep clone so we don't mutate an in-memory cached object accidentally
|
||||
collectionToReturn = JSON.parse(JSON.stringify(baseCollection));
|
||||
|
||||
for (const feature of collectionToReturn.features!) {
|
||||
try {
|
||||
const enrichResult = await enrichFeatureWithGHS(feature, enrichOptions);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user