From d4489f24a05911d1395e8473fe86c3442d9397ee Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 2 Feb 2026 12:22:03 +0000 Subject: fix(study): use date-based comparison with 3 AM boundary for due cards Instead of comparing due timestamps exactly (card.due <= now), compare against the next 3 AM boundary so all cards due within the current study day appear at once. This prevents new cards from trickling in throughout the day when FSRS fuzz spreads due times. https://claude.ai/code/session_01FeDztLcyGofd6nxh8ct7a3 --- src/server/repositories/card.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/server') diff --git a/src/server/repositories/card.ts b/src/server/repositories/card.ts index ac03bc6..2f14149 100644 --- a/src/server/repositories/card.ts +++ b/src/server/repositories/card.ts @@ -1,4 +1,5 @@ -import { and, eq, isNull, lte, sql } from "drizzle-orm"; +import { and, eq, isNull, lt, sql } from "drizzle-orm"; +import { getEndOfStudyDayBoundary } from "../../shared/date.js"; import { db } from "../db/index.js"; import { CardState, @@ -189,6 +190,7 @@ export const cardRepository: CardRepository = { now: Date, limit: number, ): Promise { + const boundary = getEndOfStudyDayBoundary(now); const result = await db .select() .from(cards) @@ -196,7 +198,7 @@ export const cardRepository: CardRepository = { and( eq(cards.deckId, deckId), isNull(cards.deletedAt), - lte(cards.due, now), + lt(cards.due, boundary), ), ) .orderBy(cards.due) @@ -205,6 +207,7 @@ export const cardRepository: CardRepository = { }, async countDueCards(deckId: string, now: Date): Promise { + const boundary = getEndOfStudyDayBoundary(now); const result = await db .select({ count: sql`count(*)::int` }) .from(cards) @@ -212,7 +215,7 @@ export const cardRepository: CardRepository = { and( eq(cards.deckId, deckId), isNull(cards.deletedAt), - lte(cards.due, now), + lt(cards.due, boundary), ), ); return result[0]?.count ?? 0; -- cgit v1.3-1-g0d28