refactor: universal logger and remove N+1 catalog queries
CI / check (push) Successful in 28s
CI / tests-ui (push) Failing after 32s
CI / tests-unit (push) Successful in 1m43s
CI / tests-quality (push) Successful in 1m14s
CI / tests-integration (push) Successful in 1m50s
CI / preflight (push) Skipped
CI / deploy (push) Skipped
CI / tests-imaging-browsers (push) Successful in 1m56s

- 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

+6 -6
View File
@@ -1,4 +1,5 @@
import { promises as fs } from "node:fs";
import { logger } from "@/lib/logger";
import { getByparrCookies } from "@/lib/services/byparr";
import {
detectNitroTextureFormat,
@@ -119,7 +120,7 @@ export async function downloadFile(
const stat = await fs.stat(destPath);
return { ok: true, size: stat.size };
}
console.warn(
logger.warn(
`[import-download] Download failed ${url}: ${res.status}${deterministic ? " (deterministic, not retrying)" : ` after ${maxRetries + 1} attempts`}`,
);
return { ok: false, size: 0, error: `HTTP ${res.status}` };
@@ -134,14 +135,14 @@ export async function downloadFile(
}
if (options?.validate === "swf" && !validateSwfBytes(buffer)) {
if (attempt === maxRetries) {
console.warn(`[import-download] Invalid SWF magic bytes from ${url}`);
logger.warn(`[import-download] Invalid SWF magic bytes from ${url}`);
return { ok: false, size: 0, error: "Response is not a SWF file" };
}
continue;
}
if (options?.validate === "png" && !validatePngBytes(buffer)) {
if (attempt === maxRetries) {
console.warn(`[import-download] Invalid PNG magic bytes from ${url}`);
logger.warn(`[import-download] Invalid PNG magic bytes from ${url}`);
return { ok: false, size: 0, error: "Response is not a PNG file" };
}
continue;
@@ -159,9 +160,8 @@ export async function downloadFile(
const stat = await fs.stat(destPath);
return { ok: true, size: stat.size };
}
console.warn(
`[import-download] Download error ${url}:`,
(err as Error).message,
logger.warn(
`[import-download] Download error ${url}: ${(err as Error).message}`,
);
const failure = err as {
code?: string;
@@ -1,4 +1,5 @@
import { promises as fs } from "node:fs";
import { logger } from "@/lib/logger";
const LOCK_STALE_MS = 60_000;
const LOCK_ACQUIRE_TIMEOUT_MS = 30_000;
@@ -50,7 +51,7 @@ async function waitForChain(filePath: string): Promise<void> {
if (elapsed > CHAIN_TIMEOUT_MS) {
// Previous holder took too long — break the chain
console.warn(
logger.warn(
`[gamedata-lock] Breaking stale chain for ${filePath} (held for ${elapsed}ms)`,
);
chains.delete(filePath);
@@ -70,7 +71,7 @@ async function waitForChain(filePath: string): Promise<void> {
]);
} catch {
// Chain holder timed out or crashed — break the chain
console.warn(
logger.warn(
`[gamedata-lock] Chain timeout for ${filePath}, breaking chain`,
);
chains.delete(filePath);