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,10 +626,25 @@ where c.nid == f.id
|
||||||
oldSize = os.stat(self.path)[stat.ST_SIZE]
|
oldSize = os.stat(self.path)[stat.ST_SIZE]
|
||||||
if self.db.scalar("pragma integrity_check") != "ok":
|
if self.db.scalar("pragma integrity_check") != "ok":
|
||||||
return (_("Collection is corrupt. Please see the manual."), False)
|
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
|
# delete any notes with missing cards
|
||||||
ids = self.db.list("""
|
ids = self.db.list("""
|
||||||
select id from notes where id not in (select distinct nid from cards)""")
|
select id from notes where id not in (select distinct nid from cards)""")
|
||||||
self._remNotes(ids)
|
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
|
# tags
|
||||||
self.tags.registerNotes()
|
self.tags.registerNotes()
|
||||||
# field cache
|
# field cache
|
||||||
|
|
|
@ -177,6 +177,9 @@ select id from cards where nid in (select id from notes where mid = ?)""",
|
||||||
def have(self, id):
|
def have(self, id):
|
||||||
return str(id) in self.models
|
return str(id) in self.models
|
||||||
|
|
||||||
|
def ids(self):
|
||||||
|
return self.models.keys()
|
||||||
|
|
||||||
# Tools
|
# Tools
|
||||||
##################################################
|
##################################################
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue