perf: warm code queue first paint
This commit is contained in:
@@ -158,6 +158,8 @@ type SqlExecutor = postgres.Sql | postgres.TransactionSql;
|
||||
const recentLogs: JsonValue[] = [];
|
||||
const serviceStartedAt = new Date().toISOString();
|
||||
const defaultQueueId = "default";
|
||||
const firstPaintOverviewWarmUrl = "http://code-queue.local/api/tasks/overview?limit=12&transcriptLimit=1&compact=1&selected=0&includeActive=0&stats=0&skipTrace=1";
|
||||
let firstPaintOverviewWarmInFlight: Promise<void> | null = null;
|
||||
const judgeFailRetryLimit = 3;
|
||||
const fallbackJudgeRetryLimit = 3;
|
||||
const maxTaskAttempts = 10;
|
||||
@@ -1415,6 +1417,30 @@ async function warmDatabaseOverviewQueries(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
async function warmCodeQueueFirstPaintOverview(): Promise<void> {
|
||||
if (!databaseReady) return;
|
||||
const started = performance.now();
|
||||
try {
|
||||
const response = await tasksOverviewResponse(new URL(firstPaintOverviewWarmUrl));
|
||||
await response.arrayBuffer();
|
||||
logger("info", "database_first_paint_overview_warm_complete", {
|
||||
status: response.status,
|
||||
durationMs: Math.round(performance.now() - started),
|
||||
});
|
||||
} catch (error) {
|
||||
logger("warn", "database_first_paint_overview_warm_failed", { error: errorToJson(error) });
|
||||
}
|
||||
}
|
||||
|
||||
async function warmCodeQueueFirstPaintOverviewDeduped(): Promise<void> {
|
||||
if (firstPaintOverviewWarmInFlight !== null) return firstPaintOverviewWarmInFlight;
|
||||
firstPaintOverviewWarmInFlight = warmCodeQueueFirstPaintOverview()
|
||||
.finally(() => {
|
||||
firstPaintOverviewWarmInFlight = null;
|
||||
});
|
||||
return firstPaintOverviewWarmInFlight;
|
||||
}
|
||||
|
||||
async function ensureDatabaseIndexes(): Promise<void> {
|
||||
logger("info", "database_index_maintenance_start", {});
|
||||
const started = performance.now();
|
||||
@@ -1430,18 +1456,23 @@ async function ensureDatabaseIndexes(): Promise<void> {
|
||||
}
|
||||
|
||||
function scheduleStartupDatabaseMaintenance(): void {
|
||||
setTimeout(() => {
|
||||
void warmCodeQueueFirstPaintOverviewDeduped();
|
||||
}, 100).unref?.();
|
||||
setTimeout(() => {
|
||||
void (async () => {
|
||||
const started = performance.now();
|
||||
logger("info", "database_startup_maintenance_start", {
|
||||
queueCount: state.queues.length,
|
||||
});
|
||||
await warmCodeQueueFirstPaintOverviewDeduped();
|
||||
for (const queue of state.queues) dirtyDatabaseQueueIds.add(queue.id);
|
||||
await flushDirtyTasksToDatabase(true);
|
||||
await loadClaudeQqNotificationOutboxFromDatabase();
|
||||
await ensureDatabaseIndexes();
|
||||
runGarbageCollection();
|
||||
await warmDatabaseOverviewQueries();
|
||||
await warmCodeQueueFirstPaintOverviewDeduped();
|
||||
logger("info", "database_startup_maintenance_complete", {
|
||||
databaseNotificationCount: claudeQqNotificationOutboxItemCount(),
|
||||
durationMs: Math.round(performance.now() - started),
|
||||
|
||||
Reference in New Issue
Block a user