From 7cb58c34327acb61cf75b817ca4cf6b90ccafec4 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 27 Nov 2018 19:37:46 +1000 Subject: [PATCH] update learning cutoff time periodically prevents users from having to leave and return to the deck to show cards that have become due during the study session https://anki.tenderapp.com/discussions/ankimobile/8530-ankimobile-with-experimental-schedule-not-showing-due-cards-in-realtime --- anki/schedv2.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/anki/schedv2.py b/anki/schedv2.py index 087fb56e5..6dededfe0 100644 --- a/anki/schedv2.py +++ b/anki/schedv2.py @@ -34,6 +34,7 @@ class Scheduler: self.reps = 0 self.today = None self._haveQueues = False + self._lrnCutoff = 0 self._updateCutoff() def getCard(self): @@ -433,15 +434,25 @@ select id from cards where did in %s and queue = 0 limit ?)""" # Learning queues ########################################################################## - def _resetLrnCount(self): - cutoff = intTime() + self.col.conf['collapseTime'] + # scan for any newly due learning cards every 5 minutes + def _updateLrnCutoff(self, force): + nextCutoff = intTime() + self.col.conf['collapseTime'] + if nextCutoff - self._lrnCutoff > 300 or force: + self._lrnCutoff = nextCutoff + return True + return False + def _maybeResetLrn(self, force): + if self._updateLrnCutoff(force): + self._resetLrn() + + def _resetLrnCount(self): # sub-day self.lrnCount = self.col.db.scalar(""" select count() from cards where did in %s and queue = 1 and due < ?""" % ( self._deckLimit()), - cutoff) or 0 + self._lrnCutoff) or 0 # day self.lrnCount += self.col.db.scalar(""" select count() from cards where did in %s and queue = 3 @@ -453,6 +464,7 @@ select count() from cards where did in %s and queue = 4 """ % (self._deckLimit())) def _resetLrn(self): + self._updateLrnCutoff(force=True) self._resetLrnCount() self._lrnQueue = [] self._lrnDayQueue = [] @@ -474,6 +486,7 @@ limit %d""" % (self._deckLimit(), self.reportLimit), lim=cutoff) return self._lrnQueue def _getLrnCard(self, collapse=False): + self._maybeResetLrn(force=collapse and self.lrnCount == 0) if self._fillLrn(): cutoff = time.time() if collapse: