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/routes/decks.ts | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'src/server/routes/decks.ts') diff --git a/src/server/routes/decks.ts b/src/server/routes/decks.ts index 2e170db..6a24c66 100644 --- a/src/server/routes/decks.ts +++ b/src/server/routes/decks.ts @@ -7,20 +7,25 @@ import { cardRepository, type DeckRepository, deckRepository, + type ReviewLogRepository, + reviewLogRepository, } from "../repositories/index.js"; import { createDeckSchema, updateDeckSchema } from "../schemas/index.js"; export interface DeckDependencies { deckRepo: DeckRepository; cardRepo: CardRepository; + reviewLogRepo: ReviewLogRepository; } const deckIdParamSchema = z.object({ id: z.uuid(), }); +const REVIEW_CARDS_LIMIT = 100; + export function createDecksRouter(deps: DeckDependencies) { - const { deckRepo, cardRepo } = deps; + const { deckRepo, cardRepo, reviewLogRepo } = deps; return new Hono() .use("*", authMiddleware) @@ -30,7 +35,26 @@ export function createDecksRouter(deps: DeckDependencies) { const now = new Date(); const decksWithDueCount = await Promise.all( decks.map(async (deck) => { - const dueCardCount = await cardRepo.countDueCards(deck.id, now); + const [dueNewCards, dueReviewCards, reviewedNewCards] = + await Promise.all([ + cardRepo.countDueNewCards(deck.id, now), + cardRepo.countDueReviewCards(deck.id, now), + reviewLogRepo.countTodayNewCardReviews(deck.id, now), + ]); + + // Apply the same limits as the study screen + const newCardBudget = Math.max( + 0, + deck.newCardsPerDay - reviewedNewCards, + ); + const newCardsToStudy = Math.min(dueNewCards, newCardBudget); + const reviewCardsToStudy = Math.min( + dueReviewCards, + REVIEW_CARDS_LIMIT, + ); + + const dueCardCount = newCardsToStudy + reviewCardsToStudy; + return { ...deck, dueCardCount }; }), ); @@ -93,4 +117,5 @@ export function createDecksRouter(deps: DeckDependencies) { export const decks = createDecksRouter({ deckRepo: deckRepository, cardRepo: cardRepository, + reviewLogRepo: reviewLogRepository, }); -- cgit v1.3-1-g0d28