mirror of
https://github.com/ankitects/anki.git
synced 2025-09-23 16:26:40 -04:00
avoid recalculating reqs in actions like adding cards
This commit is contained in:
parent
eee099c0b2
commit
d7cb7eaea0
6 changed files with 18 additions and 15 deletions
|
@ -785,7 +785,7 @@ select id from notes where mid not in """ + ids2str(self.models.ids()))
|
||||||
if t['did'] == "None":
|
if t['did'] == "None":
|
||||||
t['did'] = None
|
t['did'] = None
|
||||||
problems.append(_("Fixed AnkiDroid deck override bug."))
|
problems.append(_("Fixed AnkiDroid deck override bug."))
|
||||||
self.models.save(m)
|
self.models.save(m, updateReqs=False)
|
||||||
if m['type'] == MODEL_STD:
|
if m['type'] == MODEL_STD:
|
||||||
# model with missing req specification
|
# model with missing req specification
|
||||||
if 'req' not in m:
|
if 'req' not in m:
|
||||||
|
|
|
@ -18,7 +18,7 @@ class PaukerImporter(NoteImporter):
|
||||||
def run(self):
|
def run(self):
|
||||||
model = addForwardReverse(self.col)
|
model = addForwardReverse(self.col)
|
||||||
model['name'] = "Pauker"
|
model['name'] = "Pauker"
|
||||||
self.col.models.save(model)
|
self.col.models.save(model, updateReqs=False)
|
||||||
self.col.models.setCurrent(model)
|
self.col.models.setCurrent(model)
|
||||||
self.model = model
|
self.model = model
|
||||||
self.initMapping()
|
self.initMapping()
|
||||||
|
|
|
@ -85,12 +85,13 @@ class ModelManager:
|
||||||
self.changed = False
|
self.changed = False
|
||||||
self.models = json.loads(json_)
|
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."
|
"Mark M modified if provided, and schedule registry flush."
|
||||||
if m and m['id']:
|
if m and m['id']:
|
||||||
m['mod'] = intTime()
|
m['mod'] = intTime()
|
||||||
m['usn'] = self.col.usn()
|
m['usn'] = self.col.usn()
|
||||||
self._updateRequired(m)
|
if updateReqs:
|
||||||
|
self._updateRequired(m)
|
||||||
if templates:
|
if templates:
|
||||||
self._syncTemplates(m)
|
self._syncTemplates(m)
|
||||||
self.changed = True
|
self.changed = True
|
||||||
|
@ -254,7 +255,7 @@ and notes.mid = ? and cards.ord = ?""", m['id'], ord)
|
||||||
self.col.modSchema(check=True)
|
self.col.modSchema(check=True)
|
||||||
m['sortf'] = idx
|
m['sortf'] = idx
|
||||||
self.col.updateFieldCache(self.nids(m))
|
self.col.updateFieldCache(self.nids(m))
|
||||||
self.save(m)
|
self.save(m, updateReqs=False)
|
||||||
|
|
||||||
def addField(self, m, field):
|
def addField(self, m, field):
|
||||||
# only mod schema if model isn't new
|
# only mod schema if model isn't new
|
||||||
|
@ -304,7 +305,7 @@ and notes.mid = ? and cards.ord = ?""", m['id'], ord)
|
||||||
# restore sort field
|
# restore sort field
|
||||||
m['sortf'] = m['flds'].index(sortf)
|
m['sortf'] = m['flds'].index(sortf)
|
||||||
self._updateFieldOrds(m)
|
self._updateFieldOrds(m)
|
||||||
self.save(m)
|
self.save(m, updateReqs=False)
|
||||||
def move(fields, oldidx=oldidx):
|
def move(fields, oldidx=oldidx):
|
||||||
val = fields[oldidx]
|
val = fields[oldidx]
|
||||||
del fields[oldidx]
|
del fields[oldidx]
|
||||||
|
@ -409,7 +410,7 @@ update cards set ord = ord - 1, usn = ?, mod = ?
|
||||||
for t in m['tmpls']:
|
for t in m['tmpls']:
|
||||||
map.append("when ord = %d then %d" % (oldidxs[id(t)], t['ord']))
|
map.append("when ord = %d then %d" % (oldidxs[id(t)], t['ord']))
|
||||||
# apply
|
# apply
|
||||||
self.save(m)
|
self.save(m, updateReqs=False)
|
||||||
self.col.db.execute("""
|
self.col.db.execute("""
|
||||||
update cards set ord = (case %s end),usn=?,mod=? where nid in (
|
update cards set ord = (case %s end),usn=?,mod=? where nid in (
|
||||||
select id from notes where mid = ?)""" % " ".join(map),
|
select id from notes where mid = ?)""" % " ".join(map),
|
||||||
|
|
|
@ -456,7 +456,7 @@ class Editor:
|
||||||
# save tags to model
|
# save tags to model
|
||||||
m = self.note.model()
|
m = self.note.model()
|
||||||
m['tags'] = self.note.tags
|
m['tags'] = self.note.tags
|
||||||
self.mw.col.models.save(m)
|
self.mw.col.models.save(m, updateReqs=False)
|
||||||
|
|
||||||
def hideCompleters(self):
|
def hideCompleters(self):
|
||||||
self.tags.hideCompleter()
|
self.tags.hideCompleter()
|
||||||
|
|
|
@ -10,6 +10,7 @@ import json
|
||||||
import unicodedata
|
import unicodedata
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
|
from aqt import AnkiQt
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
import anki.importing as importing
|
import anki.importing as importing
|
||||||
from aqt.utils import getOnlyText, getFile, showText, showWarning, openHelp, \
|
from aqt.utils import getOnlyText, getFile, showText, showWarning, openHelp, \
|
||||||
|
@ -21,7 +22,7 @@ import aqt.deckchooser
|
||||||
from anki.lang import ngettext, _
|
from anki.lang import ngettext, _
|
||||||
|
|
||||||
class ChangeMap(QDialog):
|
class ChangeMap(QDialog):
|
||||||
def __init__(self, mw, model, current):
|
def __init__(self, mw: AnkiQt, model, current):
|
||||||
QDialog.__init__(self, mw, Qt.Window)
|
QDialog.__init__(self, mw, Qt.Window)
|
||||||
self.mw = mw
|
self.mw = mw
|
||||||
self.model = model
|
self.model = model
|
||||||
|
@ -64,7 +65,7 @@ class ChangeMap(QDialog):
|
||||||
|
|
||||||
class ImportDialog(QDialog):
|
class ImportDialog(QDialog):
|
||||||
|
|
||||||
def __init__(self, mw, importer):
|
def __init__(self, mw: AnkiQt, importer):
|
||||||
QDialog.__init__(self, mw, Qt.Window)
|
QDialog.__init__(self, mw, Qt.Window)
|
||||||
self.mw = mw
|
self.mw = mw
|
||||||
self.importer = importer
|
self.importer = importer
|
||||||
|
@ -159,7 +160,7 @@ you can enter it here. Use \\t to represent tab."""),
|
||||||
did = self.deck.selectedId()
|
did = self.deck.selectedId()
|
||||||
if did != self.importer.model['did']:
|
if did != self.importer.model['did']:
|
||||||
self.importer.model['did'] = 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.col.decks.select(did)
|
||||||
self.mw.progress.start(immediate=True)
|
self.mw.progress.start(immediate=True)
|
||||||
self.mw.checkpoint(_("Import"))
|
self.mw.checkpoint(_("Import"))
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Copyright: Ankitects Pty Ltd and contributors
|
# Copyright: Ankitects Pty Ltd and contributors
|
||||||
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
from aqt import AnkiQt
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
from aqt.utils import showInfo, askUser, getText, maybeHideClose, openHelp
|
from aqt.utils import showInfo, askUser, getText, maybeHideClose, openHelp
|
||||||
|
@ -11,12 +11,13 @@ import collections
|
||||||
from anki.lang import _, ngettext
|
from anki.lang import _, ngettext
|
||||||
|
|
||||||
class Models(QDialog):
|
class Models(QDialog):
|
||||||
def __init__(self, mw, parent=None, fromMain=False):
|
def __init__(self, mw: AnkiQt, parent=None, fromMain=False):
|
||||||
self.mw = mw
|
self.mw = mw
|
||||||
self.parent = parent or mw
|
self.parent = parent or mw
|
||||||
self.fromMain = fromMain
|
self.fromMain = fromMain
|
||||||
QDialog.__init__(self, self.parent, Qt.Window)
|
QDialog.__init__(self, self.parent, Qt.Window)
|
||||||
self.col = mw.col
|
self.col = mw.col
|
||||||
|
assert(self.col)
|
||||||
self.mm = self.col.models
|
self.mm = self.col.models
|
||||||
self.mw.checkpoint(_("Note Types"))
|
self.mw.checkpoint(_("Note Types"))
|
||||||
self.form = aqt.forms.models.Ui_Dialog()
|
self.form = aqt.forms.models.Ui_Dialog()
|
||||||
|
@ -56,7 +57,7 @@ class Models(QDialog):
|
||||||
txt = getText(_("New name:"), default=self.model['name'])
|
txt = getText(_("New name:"), default=self.model['name'])
|
||||||
if txt[1] and txt[0]:
|
if txt[1] and txt[0]:
|
||||||
self.model['name'] = txt[0]
|
self.model['name'] = txt[0]
|
||||||
self.mm.save(self.model)
|
self.mm.save(self.model, updateReqs=False)
|
||||||
self.updateModelsList()
|
self.updateModelsList()
|
||||||
|
|
||||||
def updateModelsList(self):
|
def updateModelsList(self):
|
||||||
|
@ -121,7 +122,7 @@ class Models(QDialog):
|
||||||
self.model['latexPost'] = str(frm.latexFooter.toPlainText())
|
self.model['latexPost'] = str(frm.latexFooter.toPlainText())
|
||||||
|
|
||||||
def saveModel(self):
|
def saveModel(self):
|
||||||
self.mm.save(self.model)
|
self.mm.save(self.model, updateReqs=False)
|
||||||
|
|
||||||
def _tmpNote(self):
|
def _tmpNote(self):
|
||||||
self.mm.setCurrent(self.model)
|
self.mm.setCurrent(self.model)
|
||||||
|
|
Loading…
Reference in a new issue