refactor: universal logger and remove N+1 catalog queries

- Replace all 39 console.* calls with universal logger (pino server, console browser)
- Set server-only marker on import-badge.ts
- Disable DB query logging in production
- Add bulkInsertCatalogItems: one transaction instead of N per-item inserts
- Add reserveCatalogItemIds helper for bulk ID allocation
- Optimize translateCatalogItems: single inArray batch query instead of N per-item selects
- Test mock updated for logger.debug
- biome clean, tsc clean, 3569 tests passing
This commit is contained in:
openhands committed 2026-10-17 14:29:14 +02:00
1 parent 6895eaab49
commit 59a45d2165
27 files changed
+416 -241

No files matched your search

+40
View File
@@ -534,6 +534,46 @@ export async function allocateCatalogItemId<T>(
return await insertFn(nextId);
}
/** Reserveer N sequentiële catalog item IDs uit de in-process counter, zonder
* per-item transaction. Gebruikt door bulk insert paden. */
export async function reserveCatalogItemIds(count: number): Promise<number[]> {
if (count <= 0) return [];
const now = Date.now();
if (
catalogNextId === null ||
now - catalogIdLastUsed > CATALOG_ID_REFRESH_MS
) {
let settle!: () => void;
const prev = catalogIdSeedChain;
catalogIdSeedChain = new Promise<void>((r) => {
settle = r;
});
await prev.catch((error) =>
logServerError("furni.catalog_id_chain_failed", error),
);
try {
if (
catalogNextId === null ||
Date.now() - catalogIdLastUsed > CATALOG_ID_REFRESH_MS
) {
const maxIdResult = await queryRows<{
maxId: number | bigint | null;
}>(sql`
SELECT MAX(id) as maxId FROM catalog_items
`);
catalogNextId = Number(maxIdResult[0]?.maxId ?? 0) + 1;
}
} finally {
settle();
}
}
catalogIdLastUsed = Date.now();
const start = catalogNextId;
catalogNextId += count;
return Array.from({ length: count }, (_, i) => start + i);
}
/** Test seam: drop the cached id counter between tests. */
/**