when suspending, move cards out of (re)learning

This commit is contained in:
Damien Elmes 2012-11-02 07:56:55 +09:00
parent 44415ea97f
commit d56a456319
2 changed files with 9 additions and 11 deletions

View file

@ -662,26 +662,24 @@ did = ? and queue = 3 and due <= ? limit ?""",
time.sleep(0.01)
log()
def removeFailed(self, ids=None, expiredOnly=False):
"Remove failed cards from the learning queue."
def removeLrn(self, ids=None):
"Remove cards from the learning queues."
if ids:
extra = " and id in "+ids2str(ids)
else:
# benchmarks indicate it's about 10x faster to search all decks
# with the index than scan the table
extra = " and did in "+ids2str(self.col.decks.allIds())
if expiredOnly:
extra += " and odue <= %d" % self.today
mod = self.col.db.mod
# review cards in relearning
self.col.db.execute("""
update cards set
due = odue, queue = 2, mod = %d, usn = %d, odue = 0
where queue = 1 and type = 2
where queue in (1,3) and type = 2
%s
""" % (intTime(), self.col.usn(), extra))
if expiredOnly:
# we don't want to bump the mod time when removing expired
self.col.db.mod = mod
# new cards in learning
self.forgetCards(self.col.db.list(
"select id from cards where queue in (1,3) %s" % extra))
def _lrnForDeck(self, did):
cnt = self.col.db.scalar(
@ -1216,7 +1214,7 @@ To study outside of the normal schedule, click the Custom Study button below."""
def suspendCards(self, ids):
"Suspend cards."
self.remFromDyn(ids)
self.removeFailed(ids)
self.removeLrn(ids)
self.col.db.execute(
"update cards set queue=-1,mod=?,usn=? where id in "+
ids2str(ids), intTime(), self.col.usn())

View file

@ -165,7 +165,7 @@ def test_learn():
c.queue = 1
c.odue = 321
c.flush()
d.sched.removeFailed()
d.sched.removeLrn()
c.load()
assert c.queue == 2
assert c.due == 321