diff --git a/anki/find.py b/anki/find.py index 3923df13c..486fb3a98 100644 --- a/anki/find.py +++ b/anki/find.py @@ -441,7 +441,7 @@ select id from facts where tags like :_tag_%d""" % c "from deckvars where key = 'leechFails')") else: # due qquery += ("select id from cards where " - "queue between 0 and 1 and due < %d") % deck.dayCutoff + "queue = 2 and due <= %d") % deck.sched.today elif type == SEARCH_FID: if fidquery: if isNeg: diff --git a/anki/storage.py b/anki/storage.py index 275a279fb..b51b30daf 100644 --- a/anki/storage.py +++ b/anki/storage.py @@ -243,10 +243,20 @@ def _upgradeSchema(db): _moveTable(db, "cards", True) # use the new order to rewrite card ids cardmap = dict(db.all("select id, rowid from cards2")) - # move back, preserving new ids + # move back, preserving new ids, and rewriting types db.execute(""" insert into cards select rowid, factId, 1, ordinal, cast(created as int), -cast(modified as int), relativeDelay, type, due, cast(interval as int), +cast(modified as int), +(case relativeDelay +when 0 then 1 +when 1 then 2 +when 2 then 0 end), +(case type +when 0 then 1 +when 1 then 2 +when 2 then 0 +else type end), +due, cast(interval as int), cast(factor*1000 as int), reps, successive, noCount, 0, 0, 0, "" from cards2 order by created""") db.execute("drop table cards2") @@ -505,15 +515,15 @@ def _postSchemaUpgrade(deck): deck.db.execute("drop table if exists %sDeleted" % t) # rewrite due times for new cards deck.db.execute(""" -update cards set due = fid where type=2""") +update cards set due = fid where type=0""") # and failed cards - deck.db.execute("update cards set edue = ? where type = 0", + deck.db.execute("update cards set edue = ? where type = 1", deck.sched.today+1) # and due cards deck.db.execute(""" update cards set due = cast( (case when due < :stamp then 0 else 1 end) + -((due-:stamp)/86400) as int)+:today where type = 1 +((due-:stamp)/86400) as int)+:today where type = 2 """, stamp=deck.sched.dayCutoff, today=deck.sched.today) # update insertion id deck.conf['nextFid'] = deck.db.scalar("select max(id) from facts")+1 diff --git a/tests/support/anki12.anki b/tests/support/anki12.anki index 226abcab8..24d027556 100644 Binary files a/tests/support/anki12.anki and b/tests/support/anki12.anki differ diff --git a/tests/test_deck.py b/tests/test_deck.py index 23d91861c..8f4e9c2a1 100644 --- a/tests/test_deck.py +++ b/tests/test_deck.py @@ -121,6 +121,8 @@ def test_upgrade(): print "upgrade to", dst shutil.copy(src, dst) deck = Deck(dst) + # 3 new, 2 failed, 1 due + assert deck.sched.counts() == (3,2,1) # now's a good time to test the integrity check too deck.fixIntegrity()