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

View file

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