wrap due numbers instead of capping them, and add warning

Wrapping (mostly) preserves the original card order, and starting
at 1M makes it easier for users to find the cards with the high
due numbers even after they have wrapped.

related discussion:
https://anki.tenderapp.com/discussions/ankidesktop/33664-due-value-of-new-card-being-1000000
This commit is contained in:
Damien Elmes 2019-04-29 18:17:33 +10:00
parent 3716feb1c4
commit 599f57494b

View File

@ -754,6 +754,7 @@ select id from notes where mid = ?) limit 1""" %
def fixIntegrity(self):
"Fix possible problems and rebuild caches."
problems = []
curs = self.db.cursor()
self.save()
oldSize = os.stat(self.path)[stat.ST_SIZE]
if self.db.scalar("pragma integrity_check") != "ok":
@ -847,10 +848,13 @@ select id from cards where odid > 0 and did in %s""" % ids2str(dids))
# field cache
for m in self.models.all():
self.updateFieldCache(self.models.nids(m))
# new cards can't have a due position > 32 bits
self.db.execute("""
update cards set due = 1000000, mod = ?, usn = ? where due > 1000000
and type = 0""", intTime(), self.usn())
# new cards can't have a due position > 32 bits, so wrap items over
# 2 million back to 1 million
curs.execute("""
update cards set due=1000000+due%1000000,mod=?,usn=? where due>=1000000
and type=0""", [intTime(), self.usn()])
if curs.rowcount:
problems.append("Found %d new cards with a due number >= 1,000,000 - consider repositioning them in the Browse screen." % curs.rowcount)
# new card position
self.conf['nextPos'] = self.db.scalar(
"select max(due)+1 from cards where type = 0") or 0
@ -863,8 +867,6 @@ and type = 0""", intTime(), self.usn())
"update cards set due = ?, ivl = 1, mod = ?, usn = ? where id in %s"
% ids2str(ids), self.sched.today, intTime(), self.usn())
# v2 sched had a bug that could create decimal intervals
curs = self.db.cursor()
curs.execute("update cards set ivl=round(ivl),due=round(due) where ivl!=round(ivl) or due!=round(due)")
if curs.rowcount:
problems.append("Fixed %d cards with v2 scheduler bug." % curs.rowcount)