mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 08:46:37 -04:00
random ids should start at 1
This commit is contained in:
parent
82a3443abe
commit
1641256da4
2 changed files with 10 additions and 6 deletions
|
@ -233,7 +233,7 @@ qconf=?, conf=?, data=?""",
|
|||
fact.flush()
|
||||
# randomize?
|
||||
if self.randomNew():
|
||||
due = random.randrange(0, 1000000)
|
||||
due = random.randrange(1, 1000000)
|
||||
else:
|
||||
due = fact.id
|
||||
# add cards
|
||||
|
|
|
@ -226,6 +226,10 @@ queue = 0 %s order by due limit %d""" % (self._groupLimit(),
|
|||
self._updateNewCardRatio()
|
||||
|
||||
def _getNewCard(self):
|
||||
# We rely on sqlite to return the cards in id order. This may not
|
||||
# correspond to the 'ord' order. The alternative would be to do
|
||||
# something like due = fid*100+ord, but then we have no efficient way
|
||||
# of spacing siblings as we'd need to fetch the fid as well.
|
||||
if self.newQueue:
|
||||
(id, due) = self.newQueue.pop()
|
||||
# move any siblings to the end?
|
||||
|
@ -549,7 +553,7 @@ queue = 2 %s and due <= :lim order by %s limit %d""" % (
|
|||
self.suspendCards([card.id])
|
||||
card.queue = -1
|
||||
elif a == 2:
|
||||
self.resetCards([card.id])
|
||||
self.forgetCards([card.id])
|
||||
card.due = 1000000
|
||||
# notify UI
|
||||
runHook("leech", card)
|
||||
|
@ -745,6 +749,8 @@ queue = 2 %s and due <= :lim order by %s limit %d""" % (
|
|||
# Resetting
|
||||
##########################################################################
|
||||
|
||||
# fixme: order
|
||||
|
||||
def forgetCards(self, ids):
|
||||
"Put cards back in the new queue."
|
||||
sql = """
|
||||
|
@ -780,18 +786,17 @@ queue = 1,
|
|||
type = 1,
|
||||
where id = :id""", vals)
|
||||
|
||||
# Reordering
|
||||
# Random<->ordered new cards
|
||||
##########################################################################
|
||||
|
||||
def randomizeCards(self, cardIds=None):
|
||||
"Randomize 'due' on all new cards."
|
||||
now = intTime()
|
||||
query = "select distinct fid from cards where type = 0"
|
||||
if cardIds:
|
||||
query += " and id in %s" % ids2str(cardIds)
|
||||
fids = self.deck.db.list(query)
|
||||
data = [{'fid': fid,
|
||||
'rand': random.randrange(0, 1000000),
|
||||
'rand': random.randrange(1, 1000000),
|
||||
'now': now} for fid in fids]
|
||||
self.deck.db.executemany("""
|
||||
update cards
|
||||
|
@ -801,7 +806,6 @@ where fid = :fid
|
|||
and type = 0""", data)
|
||||
|
||||
def orderCards(self):
|
||||
"Set 'due' to card creation time."
|
||||
self.deck.db.execute("""
|
||||
update cards set
|
||||
due = fid,
|
||||
|
|
Loading…
Reference in a new issue