groceries: stats page with nightly snapshot (battles, basket, promos, CPI, range)
All checks were successful
Deploy production / deploy (push) Successful in 1m19s

This commit is contained in:
2026-10-25 20:38:55 +00:00
parent c4397e9d59
commit a6ef263c7e
11 changed files with 35731 additions and 2 deletions

View File

@@ -0,0 +1,14 @@
// Recompute the grocery analytics snapshot (/trackers/groceries/stats) without importing.
// bun scripts/groceries-stats.ts
// The nightly import (scripts/groceries-import.ts) runs this at the end, under the import lock.
import postgres from 'postgres';
import { computeStats } from '../src/lib/server/groceries/stats';
if (!process.env.DB_URL) throw new Error('DB_URL is not set');
const log = (m: string) => console.log(`[${new Date().toISOString().slice(11, 19)}Z] ${m}`);
const sql = postgres(process.env.DB_URL, { max: 1, connect_timeout: 10, onnotice: () => {} });
try {
await computeStats(sql, log);
} finally {
await sql.end();
}