Merge pull request #240 from maiself/avoid-reordering-when-importing

Avoid reordering entire deck when importing notes
This commit is contained in:
Damien Elmes 2018-07-11 15:24:13 +10:00 committed by GitHub
commit e006cb9e6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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) snids = ids2str(nids)
have = {} have = {}
dids = {} dids = {}
for id, nid, ord, did, odid in self.db.execute( dues = {}
"select id, nid, ord, did, odid from cards where nid in "+snids): 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 # existing cards
if nid not in have: if nid not in have:
have[nid] = {} have[nid] = {}
@ -369,6 +370,11 @@ crt=?, mod=?, scm=?, dty=?, usn=?, ls=?, conf=?""",
else: else:
# first card or multiple cards in same deck # first card or multiple cards in same deck
dids[nid] = did dids[nid] = did
# save due
if odid != 0:
due = odue
if nid not in dues:
dues[nid] = due
# build cards for each note # build cards for each note
data = [] data = []
ts = maxID(self.db) ts = maxID(self.db)
@ -380,6 +386,7 @@ crt=?, mod=?, scm=?, dty=?, usn=?, ls=?, conf=?""",
model = self.models.get(mid) model = self.models.get(mid)
avail = self.models.availOrds(model, flds) avail = self.models.availOrds(model, flds)
did = dids.get(nid) or model['did'] did = dids.get(nid) or model['did']
due = dues.get(nid)
# add any missing cards # add any missing cards
for t in self._tmplsFromOrds(model, avail): for t in self._tmplsFromOrds(model, avail):
doHave = nid in have and t['ord'] in have[nid] doHave = nid in have and t['ord'] in have[nid]
@ -390,11 +397,11 @@ crt=?, mod=?, scm=?, dty=?, usn=?, ls=?, conf=?""",
did = 1 did = 1
# if the deck doesn't exist, use default instead # if the deck doesn't exist, use default instead
did = self.decks.get(did)['id'] did = self.decks.get(did)['id']
# we'd like to use the same due# as sibling cards, but we # use sibling due# if there is one, else use a new id
# can't retrieve that quickly, so we give it a new id if due is None:
# instead due = self.nextID("pos")
data.append((ts, nid, did, t['ord'], data.append((ts, nid, did, t['ord'],
now, usn, self.nextID("pos"))) now, usn, due))
ts += 1 ts += 1
# note any cards that need removing # note any cards that need removing
if nid in have: if nid in have:

View File

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