avoid reordering entire deck when importing notes

No need to reorder existing cards, which may have been manually
ordered by the user, when importing notes if we can give cards
a proper due number from the start. Retrieving any sibling's
due number for this is easy as all relevant cards will have
already been queried for when generating the new cards.
This commit is contained in:
Mai Lavelle 2018-06-30 03:07:13 -04:00
parent 918c4269c6
commit 128bfcd481
2 changed files with 13 additions and 8 deletions

View File

@ -351,8 +351,9 @@ crt=?, mod=?, scm=?, dty=?, usn=?, ls=?, conf=?""",
snids = ids2str(nids)
have = {}
dids = {}
for id, nid, ord, did, odid in self.db.execute(
"select id, nid, ord, did, odid from cards where nid in "+snids):
dues = {}
for id, nid, ord, did, due, odue, odid in self.db.execute(
"select id, nid, ord, did, due, odue, odid from cards where nid in "+snids):
# existing cards
if nid not in have:
have[nid] = {}
@ -369,6 +370,11 @@ crt=?, mod=?, scm=?, dty=?, usn=?, ls=?, conf=?""",
else:
# first card or multiple cards in same deck
dids[nid] = did
# save due
if odid != 0:
due = odue
if nid not in dues:
dues[nid] = due
# build cards for each note
data = []
ts = maxID(self.db)
@ -380,6 +386,7 @@ crt=?, mod=?, scm=?, dty=?, usn=?, ls=?, conf=?""",
model = self.models.get(mid)
avail = self.models.availOrds(model, flds)
did = dids.get(nid) or model['did']
due = dues.get(nid)
# add any missing cards
for t in self._tmplsFromOrds(model, avail):
doHave = nid in have and t['ord'] in have[nid]
@ -390,11 +397,11 @@ crt=?, mod=?, scm=?, dty=?, usn=?, ls=?, conf=?""",
did = 1
# if the deck doesn't exist, use default instead
did = self.decks.get(did)['id']
# we'd like to use the same due# as sibling cards, but we
# can't retrieve that quickly, so we give it a new id
# instead
# use sibling due# if there is one, else use a new id
if due is None:
due = self.nextID("pos")
data.append((ts, nid, did, t['ord'],
now, usn, self.nextID("pos")))
now, usn, due))
ts += 1
# note any cards that need removing
if nid in have:

View File

@ -197,8 +197,6 @@ class NoteImporter(Importer):
# in order due?
if conf['new']['order'] == NEW_CARDS_RANDOM:
self.col.sched.randomizeCards(did)
else:
self.col.sched.orderCards(did)
part1 = ngettext("%d note added", "%d notes added", len(new)) % len(new)
part2 = ngettext("%d note updated", "%d notes updated",