mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 15:02:21 -04:00
handle x->y & y->x in card model rename, big speed increase for update qa
This commit is contained in:
parent
d44c3792e9
commit
ca8e592840
1 changed files with 13 additions and 7 deletions
20
anki/deck.py
20
anki/deck.py
|
@ -1161,7 +1161,7 @@ select id, lastFontColour from cardModels""")])
|
||||||
# field remapping
|
# field remapping
|
||||||
if fieldMap:
|
if fieldMap:
|
||||||
changed = True
|
changed = True
|
||||||
self.startProgress(len(fieldMap)+1, title)
|
self.startProgress(len(fieldMap)+1)
|
||||||
seen = {}
|
seen = {}
|
||||||
for (old, new) in fieldMap.items():
|
for (old, new) in fieldMap.items():
|
||||||
self.updateProgress(_("Changing fields..."))
|
self.updateProgress(_("Changing fields..."))
|
||||||
|
@ -1202,9 +1202,10 @@ modelId = :id
|
||||||
where id in %s""" % fids, t=time.time(), id=newModel.id)
|
where id in %s""" % fids, t=time.time(), id=newModel.id)
|
||||||
self.finishProgress()
|
self.finishProgress()
|
||||||
# template remapping
|
# template remapping
|
||||||
self.startProgress(len(cardMap)+2)
|
self.startProgress(len(cardMap)+3)
|
||||||
|
toChange = []
|
||||||
|
self.updateProgress(_("Changing cards..."))
|
||||||
for (old, new) in cardMap.items():
|
for (old, new) in cardMap.items():
|
||||||
self.updateProgress(_("Changing cards..."))
|
|
||||||
if not new:
|
if not new:
|
||||||
# delete
|
# delete
|
||||||
self.s.statement("""
|
self.s.statement("""
|
||||||
|
@ -1212,13 +1213,18 @@ delete from cards
|
||||||
where cardModelId = :cid and
|
where cardModelId = :cid and
|
||||||
factId in %s""" % fids, cid=old.id)
|
factId in %s""" % fids, cid=old.id)
|
||||||
elif old != new:
|
elif old != new:
|
||||||
# change
|
# gather ids so we can rename x->y and y->x
|
||||||
self.s.statement("""
|
ids = self.s.column0("""
|
||||||
|
select id from cards where
|
||||||
|
cardModelId = :id and factId in %s""" % fids, id=old.id)
|
||||||
|
toChange.append((new, ids))
|
||||||
|
for (new, ids) in toChange:
|
||||||
|
self.updateProgress()
|
||||||
|
self.s.statement("""
|
||||||
update cards set
|
update cards set
|
||||||
cardModelId = :new,
|
cardModelId = :new,
|
||||||
ordinal = :ord
|
ordinal = :ord
|
||||||
where cardModelId = :old
|
where id in %s""" % ids2str(ids), new=new.id, ord=new.ordinal)
|
||||||
and factId in %s""" % fids, new=new.id, old=old.id, ord=new.ordinal)
|
|
||||||
self.updateProgress()
|
self.updateProgress()
|
||||||
self.updateCardQACacheFromIds(factIds, type="facts")
|
self.updateCardQACacheFromIds(factIds, type="facts")
|
||||||
self.flushMod()
|
self.flushMod()
|
||||||
|
|
Loading…
Reference in a new issue