mirror of
https://github.com/pupperpowell/bibdle.git
synced 2026-10-22 13:54:10 -04:00
fix(stats): finalize snapshots on the verse-day window
A verse date is a player's local calendar day, spanning D-1 10:00Z (UTC+14) through D+1 12:00Z (UTC-12). The old UTC end-of-day cutoff both dropped late-night finishes in negative timezones and could persist a partial day. - Scope snapshot loads by the verse date column; use completedBefore only to pin an in-progress point-in-time build. - Gate persistence on isDayClosed (D+1 12:00Z); open days are computed live and never written. - Build the cron snapshot for latestClosedDate instead of EST yesterday, and read the same date for the community page. - Add all-time best single day to snapshot totals. - Bump PAYLOAD_SCHEMA_VERSION to 4 and extend snapshot/window tests.
This commit is contained in:
1 parent
45ffa39f2a
commit
a562ee3cc9
10 files changed
+198
-52
No files matched your search
@@ -1,13 +1,13 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import type { RequestHandler } from './$types';
|
||||
import { addDays } from '$lib/server/stats/dates';
|
||||
import { latestClosedDate } from '$lib/server/stats/dates';
|
||||
import { buildSnapshot } from '$lib/server/stats/snapshot';
|
||||
import { sendDigest } from '$lib/server/stats/digest';
|
||||
|
||||
/**
|
||||
* Daily snapshot build trigger. Protected by `Authorization: Bearer $CRON_SECRET`
|
||||
* (same pattern as `/api/send-daily-verse`). Builds yesterday in `America/New_York`
|
||||
* and then sends the digest.
|
||||
* (same pattern as `/api/send-daily-verse`). Builds the most recent date whose
|
||||
* global data window has closed, then sends the digest.
|
||||
*/
|
||||
export const POST: RequestHandler = async ({ request }) => {
|
||||
const cronSecret = Bun.env.CRON_SECRET;
|
||||
@@ -16,10 +16,9 @@ export const POST: RequestHandler = async ({ request }) => {
|
||||
return json({ error: 'Unauthorized' }, { status: 401 });
|
||||
}
|
||||
|
||||
const todayEst = new Date().toLocaleDateString('en-CA', { timeZone: 'America/New_York' });
|
||||
const yesterday = addDays(todayEst, -1);
|
||||
const date = latestClosedDate();
|
||||
|
||||
const { snapshot } = await buildSnapshot(yesterday, {
|
||||
const { snapshot } = await buildSnapshot(date, {
|
||||
kind: 'scheduled',
|
||||
replace: true
|
||||
});
|
||||
@@ -27,5 +26,5 @@ export const POST: RequestHandler = async ({ request }) => {
|
||||
// Digest failure must never fail the build.
|
||||
await sendDigest(snapshot.payload);
|
||||
|
||||
return json({ ok: true, date: yesterday, buildKind: 'scheduled' });
|
||||
return json({ ok: true, date, buildKind: 'scheduled' });
|
||||
};
|
||||
Reference in new issue
Block a user