Fix aircraft backfill

This commit is contained in:
2026-06-27 16:44:16 -04:00
parent 570ed1e749
commit 404f3971c4

View File

@@ -235,31 +235,21 @@ export async function enrichAircraft(a) {
// 2. Race the two external sources // 2. Race the two external sources
if(noRecord.includes(icao)) return { icao, ...a, type: 'unknown' }; if(noRecord.includes(icao)) return { icao, ...a, type: 'unknown' };
let found = await Promise.any([ let found = await Promise.any([
fetchHexDb(icao).then(resp => { fetchHexDb(icao),
console.log(`source1: ${icao}`, resp); scrapeHexDatabase(icao),
return resp;
}),
scrapeHexDatabase(icao).then(resp => {
console.log(`source2: ${icao}`, resp);
return resp;
}),
]).catch(() => null); ]).catch(() => null);
if(!found) {
// Merge with any partial DB row we already have
const merged = { ...row, ...found };
if(!merged.aircraft) {
noRecord.push(icao); noRecord.push(icao);
return { icao, ...a, type: 'unknown' }; return { icao, ...a, type: 'unknown' };
} }
// 3. Backfill manufacturer/model/engines from similar aircraft type in DB // 3. Backfill manufacturer/model/engines from similar aircraft type in DB
const merged = { ...row, ...found };
if (merged.aircraft && (!merged.manufacturer || !merged.model)) { if (merged.aircraft && (!merged.manufacturer || !merged.model)) {
const similar = backfillFromSimilar(merged.aircraft); const similar = backfillFromSimilar(merged.aircraft);
Object.assign(merged, { ...similar, ...merged }); // don't overwrite fetched data Object.assign(merged, similar);
} }
console.log(`Backfilling: ${icao}`, merged);
// 4. Save back to DB // 4. Save back to DB
if (found) { if (found) {
db.prepare(` db.prepare(`
@@ -291,8 +281,7 @@ export async function enrichAircraft(a) {
}); });
} }
const m = { icao, ...a, ...merged }; return {icao, ...a, ...merged, type: classifyAircraft(merged) }
return {...m, type: classifyAircraft(m) }
} }
export async function getADSB() { export async function getADSB() {