avoid recalculating reqs in actions like adding cards

This commit is contained in:
Damien Elmes 2019-12-16 20:27:58 +10:00
parent eee099c0b2
commit d7cb7eaea0
6 changed files with 18 additions and 15 deletions

View file

@ -785,7 +785,7 @@ select id from notes where mid not in """ + ids2str(self.models.ids()))
if t['did'] == "None":
t['did'] = None
problems.append(_("Fixed AnkiDroid deck override bug."))
self.models.save(m)
self.models.save(m, updateReqs=False)
if m['type'] == MODEL_STD:
# model with missing req specification
if 'req' not in m:

View file

@ -18,7 +18,7 @@ class PaukerImporter(NoteImporter):
def run(self):
model = addForwardReverse(self.col)
model['name'] = "Pauker"
self.col.models.save(model)
self.col.models.save(model, updateReqs=False)
self.col.models.setCurrent(model)
self.model = model
self.initMapping()

View file

@ -85,11 +85,12 @@ class ModelManager:
self.changed = False
self.models = json.loads(json_)
def save(self, m=None, templates=False):
def save(self, m=None, templates=False, updateReqs=True):
"Mark M modified if provided, and schedule registry flush."
if m and m['id']:
m['mod'] = intTime()
m['usn'] = self.col.usn()
if updateReqs:
self._updateRequired(m)
if templates:
self._syncTemplates(m)
@ -254,7 +255,7 @@ and notes.mid = ? and cards.ord = ?""", m['id'], ord)
self.col.modSchema(check=True)
m['sortf'] = idx
self.col.updateFieldCache(self.nids(m))
self.save(m)
self.save(m, updateReqs=False)
def addField(self, m, field):
# only mod schema if model isn't new
@ -304,7 +305,7 @@ and notes.mid = ? and cards.ord = ?""", m['id'], ord)
# restore sort field
m['sortf'] = m['flds'].index(sortf)
self._updateFieldOrds(m)
self.save(m)
self.save(m, updateReqs=False)
def move(fields, oldidx=oldidx):
val = fields[oldidx]
del fields[oldidx]
@ -409,7 +410,7 @@ update cards set ord = ord - 1, usn = ?, mod = ?
for t in m['tmpls']:
map.append("when ord = %d then %d" % (oldidxs[id(t)], t['ord']))
# apply
self.save(m)
self.save(m, updateReqs=False)
self.col.db.execute("""
update cards set ord = (case %s end),usn=?,mod=? where nid in (
select id from notes where mid = ?)""" % " ".join(map),

View file

@ -456,7 +456,7 @@ class Editor:
# save tags to model
m = self.note.model()
m['tags'] = self.note.tags
self.mw.col.models.save(m)
self.mw.col.models.save(m, updateReqs=False)
def hideCompleters(self):
self.tags.hideCompleter()

View file

@ -10,6 +10,7 @@ import json
import unicodedata
import shutil
from aqt import AnkiQt
from aqt.qt import *
import anki.importing as importing
from aqt.utils import getOnlyText, getFile, showText, showWarning, openHelp, \
@ -21,7 +22,7 @@ import aqt.deckchooser
from anki.lang import ngettext, _
class ChangeMap(QDialog):
def __init__(self, mw, model, current):
def __init__(self, mw: AnkiQt, model, current):
QDialog.__init__(self, mw, Qt.Window)
self.mw = mw
self.model = model
@ -64,7 +65,7 @@ class ChangeMap(QDialog):
class ImportDialog(QDialog):
def __init__(self, mw, importer):
def __init__(self, mw: AnkiQt, importer):
QDialog.__init__(self, mw, Qt.Window)
self.mw = mw
self.importer = importer
@ -159,7 +160,7 @@ you can enter it here. Use \\t to represent tab."""),
did = self.deck.selectedId()
if did != self.importer.model['did']:
self.importer.model['did'] = did
self.mw.col.models.save(self.importer.model)
self.mw.col.models.save(self.importer.model, updateReqs=False)
self.mw.col.decks.select(did)
self.mw.progress.start(immediate=True)
self.mw.checkpoint(_("Import"))

View file

@ -1,6 +1,6 @@
# Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
from aqt import AnkiQt
from aqt.qt import *
from operator import itemgetter
from aqt.utils import showInfo, askUser, getText, maybeHideClose, openHelp
@ -11,12 +11,13 @@ import collections
from anki.lang import _, ngettext
class Models(QDialog):
def __init__(self, mw, parent=None, fromMain=False):
def __init__(self, mw: AnkiQt, parent=None, fromMain=False):
self.mw = mw
self.parent = parent or mw
self.fromMain = fromMain
QDialog.__init__(self, self.parent, Qt.Window)
self.col = mw.col
assert(self.col)
self.mm = self.col.models
self.mw.checkpoint(_("Note Types"))
self.form = aqt.forms.models.Ui_Dialog()
@ -56,7 +57,7 @@ class Models(QDialog):
txt = getText(_("New name:"), default=self.model['name'])
if txt[1] and txt[0]:
self.model['name'] = txt[0]
self.mm.save(self.model)
self.mm.save(self.model, updateReqs=False)
self.updateModelsList()
def updateModelsList(self):
@ -121,7 +122,7 @@ class Models(QDialog):
self.model['latexPost'] = str(frm.latexFooter.toPlainText())
def saveModel(self):
self.mm.save(self.model)
self.mm.save(self.model, updateReqs=False)
def _tmpNote(self):
self.mm.setCurrent(self.model)