mirror of
https://github.com/ankitects/anki.git
synced 2025-11-06 20:57:13 -05:00
add back card deletion count
cheaper to look up now that there's an index on notes.mid
This commit is contained in:
parent
00db72e365
commit
f650e5557f
2 changed files with 31 additions and 10 deletions
|
|
@ -443,6 +443,15 @@ class ModelManager:
|
|||
self.reposition_template(m, template, idx)
|
||||
self.save(m)
|
||||
|
||||
def template_use_count(self, ntid: int, ord: int) -> int:
|
||||
return self.col.db.scalar(
|
||||
"""
|
||||
select count() from cards, notes where cards.nid = notes.id
|
||||
and notes.mid = ? and cards.ord = ?""",
|
||||
ntid,
|
||||
ord,
|
||||
)
|
||||
|
||||
# Model changing
|
||||
##########################################################################
|
||||
# - maps are ord->ord, and there should not be duplicate targets
|
||||
|
|
|
|||
|
|
@ -34,8 +34,6 @@ from aqt.utils import (
|
|||
)
|
||||
from aqt.webview import AnkiWebView
|
||||
|
||||
# fixme: card count when removing
|
||||
|
||||
|
||||
class CardLayout(QDialog):
|
||||
def __init__(
|
||||
|
|
@ -497,15 +495,29 @@ class CardLayout(QDialog):
|
|||
def onRemove(self):
|
||||
if len(self.templates) < 2:
|
||||
return showInfo(_("At least one card type is required."))
|
||||
|
||||
def get_count():
|
||||
return self.mm.template_use_count(self.model["id"], self.ord)
|
||||
|
||||
def on_done(fut):
|
||||
card_cnt = fut.result()
|
||||
|
||||
template = self.current_template()
|
||||
cards = ngettext("%d card", "%d cards", card_cnt) % card_cnt
|
||||
msg = _("Delete the '%(a)s' card type, and its %(b)s?") % dict(
|
||||
a=template["name"], b=_("cards")
|
||||
a=template["name"], b=cards
|
||||
)
|
||||
if not askUser(msg):
|
||||
return
|
||||
|
||||
if not self.change_tracker.mark_schema():
|
||||
return
|
||||
|
||||
self.onRemoveInner(template)
|
||||
|
||||
self.mw.taskman.with_progress(get_count, on_done)
|
||||
|
||||
def onRemoveInner(self, template) -> None:
|
||||
self.mm.remove_template(self.model, template)
|
||||
|
||||
# ensure current ordinal is within bounds
|
||||
|
|
|
|||
Loading…
Reference in a new issue