diff --git a/anki/sched.py b/anki/sched.py index 20893952b..5c35aebf2 100644 --- a/anki/sched.py +++ b/anki/sched.py @@ -421,6 +421,12 @@ limit %d""" % (self._deckLimit(), self.reportLimit), lim=self.dayCutoff) # not collapsed; add some randomness delay *= random.uniform(1, 1.25) card.due = int(time.time() + delay) + # if the queue is not empty and there's nothing else to do, make + # sure we don't put it at the head of the queue and end up showing + # it twice in a row + if self._lrnQueue and not self.revCount and not self.newCount: + smallestDue = self._lrnQueue[0][0] + card.due = max(card.due, smallestDue+1) heappush(self._lrnQueue, (card.due, card.id)) self._logLrn(card, ease, conf, leaving, type, lastLeft) diff --git a/tests/test_sched.py b/tests/test_sched.py index da3d1c0d4..51540dde4 100644 --- a/tests/test_sched.py +++ b/tests/test_sched.py @@ -191,6 +191,32 @@ def test_learn(): assert c.queue == 2 assert c.due == 321 +def test_learn_collapsed(): + d = getEmptyDeck() + # add 2 notes + f = d.newNote() + f['Front'] = u"1" + f = d.addNote(f) + f = d.newNote() + f['Front'] = u"2" + f = d.addNote(f) + # set as a learn card and rebuild queues + d.db.execute("update cards set queue=0, type=0") + d.reset() + # should get '1' first + c = d.sched.getCard() + assert c.q().endswith("1") + # pass it so it's due in 10 minutes + d.sched.answerCard(c, 2) + # get the other card + c = d.sched.getCard() + assert c.q().endswith("2") + # fail it so it's due in 1 minute + d.sched.answerCard(c, 1) + # we shouldn't get the same card again + c = d.sched.getCard() + assert not c.q().endswith("2") + def test_reviews(): d = getEmptyDeck() # add a note @@ -881,4 +907,3 @@ def test_resched(): c.load() assert c.due == d.sched.today+1 assert c.ivl == +1 -