handle randomize progress in ankiqt, add helper for updating facts

This commit is contained in:
Damien Elmes 2009-04-23 01:57:54 +09:00
parent f4997f328c
commit d1a44e308e

View file

@ -516,13 +516,13 @@ combinedDue = created, modified = :now, due = created
where id in %s""" % ids2str(ids), now=time.time(), new=0) where id in %s""" % ids2str(ids), now=time.time(), new=0)
self.flushMod() self.flushMod()
def randomizeNewCards(self): def randomizeNewCards(self, cardIds=None):
"Randomize 'due' on all new cards." "Randomize 'due' on all new cards."
self.startProgress()
self.updateProgress(_("Randomizing..."))
now = time.time() now = time.time()
fids = self.s.column0(""" query = "select distinct factId from cards where type = 2"
select distinct factId from cards where type = 2""") if cardIds:
query += " and id in %s" % ids2str(cardIds)
fids = self.s.column0(query)
data = [{'fid': fid, data = [{'fid': fid,
'rand': random.uniform(0, now), 'rand': random.uniform(0, now),
'now': now} for fid in fids] 'now': now} for fid in fids]
@ -533,19 +533,15 @@ combinedDue = max(:rand + ordinal, spaceUntil),
modified = :now modified = :now
where factId = :fid where factId = :fid
and type = 2""", data) and type = 2""", data)
self.finishProgress()
def orderNewCards(self): def orderNewCards(self):
"Set 'due' to card creation time." "Set 'due' to card creation time."
self.startProgress()
self.updateProgress(_("Ordering..."))
self.s.statement(""" self.s.statement("""
update cards set update cards set
due = created, due = created,
combinedDue = max(spaceUntil, due), combinedDue = max(spaceUntil, due),
modified = :now modified = :now
where type = 2""", now=time.time()) where type = 2""", now=time.time())
self.finishProgress()
def rescheduleCards(self, ids, min, max): def rescheduleCards(self, ids, min, max):
"Reset cards and schedule with new interval in days (min, max)." "Reset cards and schedule with new interval in days (min, max)."
@ -1404,6 +1400,17 @@ facts.modelId = :id""", id=model.id)
return return
self.updateCardQACache(ids, dirty) self.updateCardQACache(ids, dirty)
def updateCardsFromFactIds(self, ids, dirty=True):
"Update all card question/answer when model changes."
ids = self.s.all("""
select cards.id, cards.cardModelId, cards.factId, facts.modelId from
cards, facts where
cards.factId = facts.id and
facts.id in %s""" % ids2str(ids))
if not ids:
return
self.updateCardQACache(ids, dirty)
def updateCardQACacheFromIds(self, ids, type="cards"): def updateCardQACacheFromIds(self, ids, type="cards"):
"Given a list of card or fact ids, update q/a cache." "Given a list of card or fact ids, update q/a cache."
if type == "facts": if type == "facts":