don't decrement due counts when spacing

This works fine if the user is showing all cards, but if they have limited
reviews to certain categories, it can result in the counts going negative
because we decremented for cards which weren't actually due. Determining if a
card was actually due or not is an expensive operation, so instead we leave
the counts alone and make sure reviews will finish early if the new/rev counts
are non-zero but the queue is empty.
This commit is contained in:
Damien Elmes 2010-12-26 05:54:05 +09:00
parent 93a67931da
commit 63106578cd

View file

@ -673,7 +673,9 @@ limit %s""" % (self.cramOrder, self.queueLimit)))
return self.revQueue[-1][0] return self.revQueue[-1][0]
# new cards left? # new cards left?
if self.newCountToday: if self.newCountToday:
return self.getNewCard() id = self.getNewCard()
if id:
return id
if check: if check:
# check for expired cards, or new day rollover # check for expired cards, or new day rollover
self.updateCutoff() self.updateCutoff()
@ -711,12 +713,25 @@ limit %s""" % (self.cramOrder, self.queueLimit)))
return False return False
def getNewCard(self): def getNewCard(self):
if (not self.newQueue or src = None
self.spacedCards and if (self.spacedCards and
self.spacedCards[0][0] < time.time()): self.spacedCards[0][0] < time.time()):
# spaced card has expired
src = 0
elif self.newQueue:
# card left in new queue
src = 1
elif self.spacedCards:
# card left in spaced queue
src = 0
else:
# only cards spaced to another day left
return
if src == 0:
cards = self.spacedCards[0][1] cards = self.spacedCards[0][1]
self.newFromCache = True self.newFromCache = True
return cards[0] return cards[0]
else:
self.newFromCache = False self.newFromCache = False
return self.newQueue[-1][0] return self.newQueue[-1][0]
@ -870,20 +885,7 @@ where id in """
self.setUndoEnd(undoName) self.setUndoEnd(undoName)
def _spaceCards(self, card): def _spaceCards(self, card):
# update new counts
new = time.time() + self.newSpacing new = time.time() + self.newSpacing
if new > self.dueCutoff:
self.newCount -= self.s.scalar("""
select count() from cards
where factId = :fid and id != :cid
and combinedDue < :cut and type = 2
""", cid=card.id, fid=card.factId, cut=self.dueCutoff)
# update due counts
self.revCount -= self.s.scalar("""
select count() from cards
where factId = :fid and id != :cid
and combinedDue < :cut and type = 1
""", cid=card.id, fid=card.factId, cut=self.dueCutoff)
# space cards # space cards
self.s.statement(""" self.s.statement("""
update cards set update cards set