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
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:
1 parent
6895eaab49
commit
59a45d2165
27 files changed
+416
-241
No files matched your search
@@ -46,6 +46,7 @@ import { Textarea } from "@/components/ui/textarea";
|
||||
import { useServerAction } from "@/hooks/use-server-action";
|
||||
import { adminFetch } from "@/lib/admin-fetch";
|
||||
import { invalidateSongPickerCache } from "@/lib/client-cache/song-picker-cache";
|
||||
import { logger } from "@/lib/logger";
|
||||
import { parseTraxChannels } from "@/lib/trax-format";
|
||||
import { TraxPlayer } from "./trax-player";
|
||||
|
||||
@@ -455,7 +456,9 @@ function UploadDialog({
|
||||
onOpenChange(false);
|
||||
onUploaded();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
logger.error("Sound upload failed", {
|
||||
err: err as Error,
|
||||
});
|
||||
toast.error("Network error during upload.");
|
||||
} finally {
|
||||
setUploading(false);
|
||||
|
||||
@@ -19,6 +19,7 @@ import { Loader2, Play, Square } from "lucide-react";
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { logger } from "@/lib/logger";
|
||||
import { TRAX_TICK_SECONDS, type TraxChannel } from "@/lib/trax-format";
|
||||
|
||||
const TICK_SECONDS = TRAX_TICK_SECONDS;
|
||||
@@ -127,7 +128,9 @@ export function TraxPlayer({
|
||||
buffers.set(id, buf);
|
||||
} catch (err) {
|
||||
failed++;
|
||||
console.warn(`[trax] failed to load sample ${id}:`, err);
|
||||
logger.warn(`[trax] failed to load sample ${id}`, {
|
||||
err: err as Error,
|
||||
});
|
||||
} finally {
|
||||
done++;
|
||||
setLoaded(done);
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
bundleExistsInDir,
|
||||
bundleWritePathInDir,
|
||||
} from "@/lib/furni/bundle-file";
|
||||
import { logger } from "@/lib/logger";
|
||||
import { PERMS } from "@/lib/permissions";
|
||||
import { getFurniAssetDirs } from "@/lib/services/furni-asset-dirs";
|
||||
import {
|
||||
@@ -315,9 +316,8 @@ export const POST = withAdmin(
|
||||
try {
|
||||
languages = await buildLocalizedFurniDataFiles();
|
||||
} catch (err) {
|
||||
console.warn(
|
||||
"[batch-regen] Localized furnidata build failed:",
|
||||
(err as Error).message,
|
||||
logger.warn(
|
||||
`[batch-regen] Localized furnidata build failed: ${(err as Error).message}`,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import { apiError } from "@/lib/api";
|
||||
import { withAdmin } from "@/lib/api-handler";
|
||||
import { getRequestId } from "@/lib/foundation/request-context";
|
||||
import type { ImportJob } from "@/lib/furni/import-job";
|
||||
import { logger } from "@/lib/logger";
|
||||
import { PERMS } from "@/lib/permissions";
|
||||
import { logAudit } from "@/lib/services/audit";
|
||||
import { getSource } from "@/lib/services/clone-sources";
|
||||
@@ -112,10 +113,9 @@ export const POST = withAdmin(
|
||||
await store.save(job);
|
||||
return job;
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
"[import-furni] Could not create durable batch job",
|
||||
error,
|
||||
);
|
||||
logger.warn("[import-furni] Could not create durable batch job", {
|
||||
err: error as Error,
|
||||
});
|
||||
return null;
|
||||
}
|
||||
})();
|
||||
@@ -156,7 +156,9 @@ export const POST = withAdmin(
|
||||
try {
|
||||
await store.save(mirrorJob);
|
||||
} catch (error) {
|
||||
console.warn("[import-furni] Checkpoint write failed", error);
|
||||
logger.warn("[import-furni] Checkpoint write failed", {
|
||||
err: error as Error,
|
||||
});
|
||||
} finally {
|
||||
saveQueued = false;
|
||||
}
|
||||
@@ -177,7 +179,9 @@ export const POST = withAdmin(
|
||||
try {
|
||||
await store.save(mirrorJob);
|
||||
} catch (error) {
|
||||
console.warn("[import-furni] Final checkpoint write failed", error);
|
||||
logger.warn("[import-furni] Final checkpoint write failed", {
|
||||
err: error as Error,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -412,9 +416,8 @@ export const POST = withAdmin(
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn(
|
||||
"[import-furni] RCON update failed after batch:",
|
||||
(err as Error).message,
|
||||
logger.warn(
|
||||
`[import-furni] RCON update failed after batch: ${(err as Error).message}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -470,15 +473,13 @@ export const POST = withAdmin(
|
||||
try {
|
||||
languages = await buildLocalizedFurniDataFiles();
|
||||
} catch (err) {
|
||||
console.warn(
|
||||
"[import-furni] Localized furnidata build failed:",
|
||||
(err as Error).message,
|
||||
logger.warn(
|
||||
`[import-furni] Localized furnidata build failed: ${(err as Error).message}`,
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn(
|
||||
"[import-furni] Post-import reconcile/ownership failed:",
|
||||
(err as Error).message,
|
||||
logger.warn(
|
||||
`[import-furni] Post-import reconcile/ownership failed: ${(err as Error).message}`,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import { apiError, apiOk } from "@/lib/api";
|
||||
import { withAdmin } from "@/lib/api-handler";
|
||||
import { db, ItemsBase, queryRows } from "@/lib/db";
|
||||
import { resolveBundleInDir } from "@/lib/furni/bundle-file";
|
||||
import { logger } from "@/lib/logger";
|
||||
import { PERMS } from "@/lib/permissions";
|
||||
import { logAudit } from "@/lib/services/audit";
|
||||
import { getFurniAssetDirs } from "@/lib/services/furni-asset-dirs";
|
||||
@@ -65,9 +66,9 @@ export const GET = withAdmin(
|
||||
|
||||
return apiOk({ metadata: json, flags });
|
||||
} catch (err) {
|
||||
console.error(
|
||||
"[nitro-editor] Failed to parse bundle:",
|
||||
(err as Error).message,
|
||||
logger.error(
|
||||
`[nitro-editor] Failed to parse bundle: ${(err as Error).message}`,
|
||||
{ err: err as Error },
|
||||
);
|
||||
return apiError("Failed to parse bundle file", 500);
|
||||
}
|
||||
@@ -156,9 +157,8 @@ export const PUT = withAdmin(
|
||||
await writeFurniData(furniData as Record<string, unknown>);
|
||||
});
|
||||
} catch (err) {
|
||||
console.warn(
|
||||
"[nitro-editor] FurnitureData.json update failed:",
|
||||
(err as Error).message,
|
||||
logger.warn(
|
||||
`[nitro-editor] FurnitureData.json update failed: ${(err as Error).message}`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -173,9 +173,8 @@ export const PUT = withAdmin(
|
||||
WHERE item_name = ${rawClassname}
|
||||
`);
|
||||
} catch (err) {
|
||||
console.warn(
|
||||
"[nitro-editor] items_base update failed:",
|
||||
(err as Error).message,
|
||||
logger.warn(
|
||||
`[nitro-editor] items_base update failed: ${(err as Error).message}`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -183,9 +182,8 @@ export const PUT = withAdmin(
|
||||
try {
|
||||
await rcon.updateItems();
|
||||
} catch (err) {
|
||||
console.warn(
|
||||
"[nitro-editor] RCON updateItems failed:",
|
||||
(err as Error).message,
|
||||
logger.warn(
|
||||
`[nitro-editor] RCON updateItems failed: ${(err as Error).message}`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -210,7 +208,7 @@ export const PUT = withAdmin(
|
||||
},
|
||||
});
|
||||
} catch (err) {
|
||||
console.warn("[nitro-editor] Audit log failed:", (err as Error).message);
|
||||
logger.warn(`[nitro-editor] Audit log failed: ${(err as Error).message}`);
|
||||
}
|
||||
|
||||
return apiOk({ dimensions: dims });
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
} from "@/lib/furni/bundle-file";
|
||||
import { isSafeAssetName, normalizeClassname } from "@/lib/furni/classname";
|
||||
import { localFurnitureStatus } from "@/lib/furni/local-presence";
|
||||
import { logger } from "@/lib/logger";
|
||||
import { PERMS } from "@/lib/permissions";
|
||||
import { logAudit } from "@/lib/services/audit";
|
||||
import { getCloneList } from "@/lib/services/clone-import";
|
||||
@@ -446,9 +447,8 @@ export const POST = withAdmin(
|
||||
try {
|
||||
await appendFurniEntriesBulk(collectedFurniEntries);
|
||||
} catch (err) {
|
||||
console.warn(
|
||||
"[import-furni] Bulk FurnitureData.json write failed:",
|
||||
(err as Error).message,
|
||||
logger.warn(
|
||||
`[import-furni] Bulk FurnitureData.json write failed: ${(err as Error).message}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -458,9 +458,8 @@ export const POST = withAdmin(
|
||||
await rcon.updateCatalog();
|
||||
await rcon.updateItems();
|
||||
} catch (err) {
|
||||
console.warn(
|
||||
"[import-furni] RCON update failed after batch:",
|
||||
(err as Error).message,
|
||||
logger.warn(
|
||||
`[import-furni] RCON update failed after batch: ${(err as Error).message}`,
|
||||
);
|
||||
}
|
||||
invalidateCatalogTotals();
|
||||
@@ -509,9 +508,8 @@ export const POST = withAdmin(
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn(
|
||||
"[import-furni] Localized furnidata build failed:",
|
||||
(err as Error).message,
|
||||
logger.warn(
|
||||
`[import-furni] Localized furnidata build failed: ${(err as Error).message}`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -588,9 +586,8 @@ export const POST = withAdmin(
|
||||
await rcon.updateCatalog();
|
||||
await rcon.updateItems();
|
||||
} catch (err) {
|
||||
console.warn(
|
||||
"[import-furni] RCON update failed:",
|
||||
(err as Error).message,
|
||||
logger.warn(
|
||||
`[import-furni] RCON update failed: ${(err as Error).message}`,
|
||||
);
|
||||
result.warnings.push("RCON cache refresh failed");
|
||||
}
|
||||
@@ -640,9 +637,8 @@ export const POST = withAdmin(
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn(
|
||||
"[import-furni] Localized patch failed:",
|
||||
(err as Error).message,
|
||||
logger.warn(
|
||||
`[import-furni] Localized patch failed: ${(err as Error).message}`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -850,9 +846,8 @@ export const PATCH = withAdmin(
|
||||
await appendFurniEntry(entry, itemType);
|
||||
}
|
||||
} catch (fdErr) {
|
||||
console.warn(
|
||||
`[regen] FurnitureData update skipped for ${item.classname}:`,
|
||||
(fdErr as Error).message,
|
||||
logger.warn(
|
||||
`[regen] FurnitureData update skipped for ${item.classname}: ${(fdErr as Error).message}`,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user