mirror of
https://github.com/pupperpowell/bibdle.git
synced 2026-04-06 01:43:32 -04:00
no longer initializes embeddings model on startup
This commit is contained in:
@@ -12,7 +12,7 @@ export const GET: RequestHandler = async ({ url }) => {
|
||||
error(400, 'Missing anonymousId or localDate');
|
||||
}
|
||||
|
||||
// Fetch all completion dates for this user, newest first
|
||||
// Fetch all completion dates for this user (stored as the user's local date)
|
||||
const rows = await db
|
||||
.select({ date: dailyCompletions.date })
|
||||
.from(dailyCompletions)
|
||||
@@ -21,15 +21,21 @@ export const GET: RequestHandler = async ({ url }) => {
|
||||
|
||||
const completedDates = new Set(rows.map((r) => r.date));
|
||||
|
||||
// Walk backwards from localDate, counting consecutive completed days
|
||||
let streak = 0;
|
||||
let cursor = new Date(`${localDate}T00:00:00`);
|
||||
// Subtract one calendar day from a YYYY-MM-DD string using UTC arithmetic —
|
||||
// this avoids any dependence on the server's local timezone or DST offsets.
|
||||
function prevDay(dateStr: string): string {
|
||||
const d = new Date(dateStr + 'T00:00:00Z');
|
||||
d.setUTCDate(d.getUTCDate() - 1);
|
||||
return d.toISOString().slice(0, 10);
|
||||
}
|
||||
|
||||
while (true) {
|
||||
const dateStr = cursor.toLocaleDateString('en-CA'); // YYYY-MM-DD
|
||||
if (!completedDates.has(dateStr)) break;
|
||||
// Walk backwards from the user's local date, counting consecutive completed days
|
||||
let streak = 0;
|
||||
let cursor = localDate;
|
||||
|
||||
while (completedDates.has(cursor)) {
|
||||
streak++;
|
||||
cursor.setDate(cursor.getDate() - 1);
|
||||
cursor = prevDay(cursor);
|
||||
}
|
||||
|
||||
return json({ streak: streak < 2 ? 0 : streak });
|
||||
|
||||
Reference in New Issue
Block a user