From 5f9792392a953271eee21004e3a49b591999b9a7 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 2 Mar 2021 10:23:06 +1000 Subject: [PATCH] don't cap child counts to parents when reviewing in v2 https://forums.ankiweb.net/t/anki-2-1-41-beta/7305/59 When originally implemented in 21023ed3e561910f41dd709e0b7a160f3cc8665a, a given deck's limit was bound by its parents. This lead to a deck list that seemed more logical in the parent limit < child limit case, as child counts couldn't exceed a parent's, but it obscured the fact that child decks could still be clicked on to show cards. And in the parent limit > child limit case, the count shown for the child on the deck list did not reflect how many cards were actually available and would be delivered. This change updates the reviewer to ignore parent limits when getting review counts for the deck, which makes the behaviour consistent with the deck list, which was recently changed to ignore parent limits. Neither solution is ideal - this was a tradeoff v2 made in order to keep fetching of review cards from multiple decks reasonably performant. The experimental scheduling work moves back to respecting limits on individual children, so this should hopefully improve in the future. Also removed _revForDeck(), which was unused. --- pylib/anki/sched.py | 21 +-------------------- pylib/anki/schedv2.py | 27 ++------------------------- 2 files changed, 3 insertions(+), 45 deletions(-) diff --git a/pylib/anki/sched.py b/pylib/anki/sched.py index 3b4ceada1..844353551 100644 --- a/pylib/anki/sched.py +++ b/pylib/anki/sched.py @@ -12,7 +12,7 @@ import anki from anki import hooks from anki.cards import Card from anki.consts import * -from anki.decks import Deck, QueueConfig +from anki.decks import QueueConfig from anki.schedv2 import Scheduler as V2 from anki.utils import ids2str, intTime @@ -428,25 +428,6 @@ and due <= ? limit ?)""", def _deckRevLimit(self, did: int) -> int: return self._deckNewLimit(did, self._deckRevLimitSingle) - def _deckRevLimitSingle(self, d: Deck) -> int: # type: ignore[override] - if d["dyn"]: - return self.reportLimit - c = self.col.decks.confForDid(d["id"]) - limit = max(0, c["rev"]["perDay"] - self.counts_for_deck_today(d["id"]).review) - return hooks.scheduler_review_limit_for_single_deck(limit, d) - - def _revForDeck(self, did: int, lim: int) -> int: # type: ignore[override] - lim = min(lim, self.reportLimit) - return self.col.db.scalar( - f""" -select count() from -(select 1 from cards where did = ? and queue = {QUEUE_TYPE_REV} -and due <= ? limit ?)""", - did, - self.today, - lim, - ) - def _resetRev(self) -> None: self._revQueue: List[Any] = [] self._revDids = self.col.decks.active()[:] diff --git a/pylib/anki/schedv2.py b/pylib/anki/schedv2.py index 1c141c757..cae96be64 100644 --- a/pylib/anki/schedv2.py +++ b/pylib/anki/schedv2.py @@ -14,7 +14,7 @@ import anki._backend.backend_pb2 as _pb from anki import hooks from anki.cards import Card from anki.consts import * -from anki.decks import Deck, DeckConfig, DeckManager, DeckTreeNode, QueueConfig +from anki.decks import Deck, DeckConfig, DeckTreeNode, QueueConfig from anki.lang import FormatTimeSpan from anki.notes import Note from anki.utils import from_json_bytes, ids2str, intTime @@ -390,9 +390,7 @@ did = ? and queue = {QUEUE_TYPE_DAY_LEARN_RELEARN} and due <= ? limit ?""", d = self.col.decks.get(self.col.decks.selected(), default=False) return self._deckRevLimitSingle(d) - def _deckRevLimitSingle( - self, d: Dict[str, Any], parentLimit: Optional[int] = None - ) -> int: + def _deckRevLimitSingle(self, d: Dict[str, Any]) -> int: # invalid deck selected? if not d: return 0 @@ -403,29 +401,8 @@ did = ? and queue = {QUEUE_TYPE_DAY_LEARN_RELEARN} and due <= ? limit ?""", c = self.col.decks.confForDid(d["id"]) lim = max(0, c["rev"]["perDay"] - self.counts_for_deck_today(d["id"]).review) - if parentLimit is not None: - lim = min(parentLimit, lim) - elif "::" in d["name"]: - for parent in self.col.decks.parents(d["id"]): - # pass in dummy parentLimit so we don't do parent lookup again - lim = min(lim, self._deckRevLimitSingle(parent, parentLimit=lim)) return hooks.scheduler_review_limit_for_single_deck(lim, d) - def _revForDeck( - self, did: int, lim: int, childMap: DeckManager.childMapNode - ) -> Any: - dids = [did] + self.col.decks.childDids(did, childMap) - lim = min(lim, self.reportLimit) - return self.col.db.scalar( - f""" -select count() from -(select 1 from cards where did in %s and queue = {QUEUE_TYPE_REV} -and due <= ? limit ?)""" - % ids2str(dids), - self.today, - lim, - ) - def _resetRev(self) -> None: self._revQueue: List[int] = []