diff --git a/apps/backend/scripts/bulldozer-payments-init.ts b/apps/backend/scripts/bulldozer-payments-init.ts index 6be12197e..6e8941838 100644 --- a/apps/backend/scripts/bulldozer-payments-init.ts +++ b/apps/backend/scripts/bulldozer-payments-init.ts @@ -34,7 +34,7 @@ import { globalPrismaClient } from "@/prisma-client"; import { throwErr } from "@hexclave/shared/dist/utils/errors"; import { wait } from "@hexclave/shared/dist/utils/promises"; -const BATCH_SIZE = 500; +const BATCH_SIZE = 100; // Fixed processing order. Resume positions are interpreted against this list. export const BACKFILL_TABLES = [ @@ -70,6 +70,13 @@ function log(message: string) { console.log(`[BulldozerBackfill] ${message}`); } +function formatDuration(ms: number): string { + if (ms < 1000) { + return `${Math.round(ms)}ms`; + } + return `${(ms / 1000).toFixed(1)}s`; +} + function lowerCustomerType(customerType: string): CustomerType { const lowered = customerType.toLowerCase(); if (lowered === "user" || lowered === "team" || lowered === "custom") { @@ -193,6 +200,7 @@ async function backfillTable( log(`[${label}] starting${cursor ? ` from cursor ${cursor.tenancyId},${cursor.id}` : ""}`); for (;;) { + const batchStartedAt = performance.now(); const batch = await fetchBatch(cursor); if (batch.length === 0) break; @@ -229,7 +237,8 @@ async function backfillTable( cursor = next; batchNumber++; - log(`[${label}] batch=${batchNumber} rows=${batch.length} total=${total}${failed > 0 ? ` failed=${failed}` : ""} cursor=${cursor.tenancyId},${cursor.id}`); + const batchDurationMs = performance.now() - batchStartedAt; + log(`[${label}] batch=${batchNumber} duration=${formatDuration(batchDurationMs)} rows=${batch.length} total=${total}${failed > 0 ? ` failed=${failed}` : ""} cursor=${cursor.tenancyId},${cursor.id}`); // A short page means we've hit the end; skip the extra empty fetch. if (batch.length < BATCH_SIZE) break;