Files
website/scripts/groceries-stats.ts
Stan Runge a6ef263c7e
All checks were successful
Deploy production / deploy (push) Successful in 1m19s
groceries: stats page with nightly snapshot (battles, basket, promos, CPI, range)
2026-10-25 20:39:35 +00:00

15 lines
644 B
TypeScript

// 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();
}