From 128bfcd481c4d532812d05d5a2b25c58f62e26b2 Mon Sep 17 00:00:00 2001 From: Mai Lavelle Date: Sat, 30 Jun 2018 03:07:13 -0400 Subject: [PATCH] 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. --- anki/collection.py | 19 +++++++++++++------ anki/importing/noteimp.py | 2 -- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/anki/collection.py b/anki/collection.py index d5b4e9dd7..76a94971a 100644 --- a/anki/collection.py +++ b/anki/collection.py @@ -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: diff --git a/anki/importing/noteimp.py b/anki/importing/noteimp.py index 14eb439b8..9231eb907 100644 --- a/anki/importing/noteimp.py +++ b/anki/importing/noteimp.py @@ -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",