From 504ff72fea72eb3d7c4cf45be1bd9620cb12a796 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Thu, 5 Feb 2026 22:49:03 +0900 Subject: fix(decks): align due card count with study screen limits The deck list was showing all due cards without applying the newCardsPerDay limit or review card limit (100), causing a mismatch with the actual number of cards available in the study screen. Co-Authored-By: Claude Opus 4.5 --- src/server/repositories/card.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/server/repositories/card.ts') diff --git a/src/server/repositories/card.ts b/src/server/repositories/card.ts index f546922..d382f4d 100644 --- a/src/server/repositories/card.ts +++ b/src/server/repositories/card.ts @@ -221,6 +221,38 @@ export const cardRepository: CardRepository = { return result[0]?.count ?? 0; }, + async countDueNewCards(deckId: string, now: Date): Promise { + const boundary = getEndOfStudyDayBoundary(now); + const result = await db + .select({ count: sql`count(*)::int` }) + .from(cards) + .where( + and( + eq(cards.deckId, deckId), + isNull(cards.deletedAt), + lt(cards.due, boundary), + eq(cards.state, CardState.New), + ), + ); + return result[0]?.count ?? 0; + }, + + async countDueReviewCards(deckId: string, now: Date): Promise { + const boundary = getEndOfStudyDayBoundary(now); + const result = await db + .select({ count: sql`count(*)::int` }) + .from(cards) + .where( + and( + eq(cards.deckId, deckId), + isNull(cards.deletedAt), + lt(cards.due, boundary), + ne(cards.state, CardState.New), + ), + ); + return result[0]?.count ?? 0; + }, + async findDueCardsWithNoteData( deckId: string, now: Date, -- cgit v1.3-1-g0d28