mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 23:42:23 -04:00
delete notes that are missing their model
This commit is contained in:
parent
958768ccfe
commit
2ee3ec8b7a
2 changed files with 19 additions and 1 deletions
|
@ -626,9 +626,24 @@ where c.nid == f.id
|
|||
oldSize = os.stat(self.path)[stat.ST_SIZE]
|
||||
if self.db.scalar("pragma integrity_check") != "ok":
|
||||
return (_("Collection is corrupt. Please see the manual."), False)
|
||||
# note types with a missing model
|
||||
ids = self.db.list("""
|
||||
select id from notes where mid not in """ + ids2str(self.models.ids()))
|
||||
if ids:
|
||||
print self.db.list("select distinct mid from notes where id in " + ids2str(ids))
|
||||
problems.append(
|
||||
ngettext("Deleted %d note with missing note type.",
|
||||
"Deleted %d notes with missing note type.", len(ids))
|
||||
% len(ids))
|
||||
self.remNotes(ids)
|
||||
# delete any notes with missing cards
|
||||
ids = self.db.list("""
|
||||
select id from notes where id not in (select distinct nid from cards)""")
|
||||
if ids:
|
||||
cnt = len(ids)
|
||||
problems.append(
|
||||
ngettext("Deleted %d note with no cards.",
|
||||
"Deleted %d notes with no cards.", cnt) % cnt)
|
||||
self._remNotes(ids)
|
||||
# tags
|
||||
self.tags.registerNotes()
|
||||
|
|
|
@ -177,6 +177,9 @@ select id from cards where nid in (select id from notes where mid = ?)""",
|
|||
def have(self, id):
|
||||
return str(id) in self.models
|
||||
|
||||
def ids(self):
|
||||
return self.models.keys()
|
||||
|
||||
# Tools
|
||||
##################################################
|
||||
|
||||
|
|
Loading…
Reference in a new issue