groceries: stats page with nightly snapshot (battles, basket, promos, CPI, range)
All checks were successful
Deploy production / deploy (push) Successful in 1m19s
All checks were successful
Deploy production / deploy (push) Successful in 1m19s
This commit is contained in:
@@ -167,8 +167,10 @@ try {
|
||||
where n.nspname = 'groceries' and c.relkind = 'r'
|
||||
`;
|
||||
if (
|
||||
Number(groceries.tables) !== 8 ||
|
||||
Number(groceries.app_rw) !== 8 ||
|
||||
// 10 = stores, items, item_prices, groups, import_runs, categories, manual_prices, synonyms,
|
||||
// stats_snapshots, item_sizes (more is fine as long as the app can read/write all of them).
|
||||
Number(groceries.tables) < 10 ||
|
||||
Number(groceries.app_rw) !== Number(groceries.tables) ||
|
||||
Number(groceries.ro_read) !== 0 ||
|
||||
groceries.public_usage
|
||||
)
|
||||
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
regroup
|
||||
} from '../src/lib/server/groceries/import';
|
||||
import { applyTaxonomy } from '../src/lib/server/groceries/taxonomy';
|
||||
import { computeStats } from '../src/lib/server/groceries/stats';
|
||||
import { SOURCES } from '../src/lib/server/groceries/sources';
|
||||
|
||||
const args = process.argv.slice(2);
|
||||
@@ -88,6 +89,12 @@ try {
|
||||
}
|
||||
await regroup(sql, log);
|
||||
await applyTaxonomy(sql, log);
|
||||
try {
|
||||
await computeStats(sql, log);
|
||||
} catch (e) {
|
||||
failed = true;
|
||||
log(`stats: FAILED ${e instanceof Error ? e.message : e}`);
|
||||
}
|
||||
} finally {
|
||||
await sql.end();
|
||||
}
|
||||
|
||||
14
scripts/groceries-stats.ts
Normal file
14
scripts/groceries-stats.ts
Normal 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();
|
||||
}
|
||||
Reference in New Issue
Block a user