delete notes that are missing their model

This commit is contained in:
Damien Elmes 2012-09-09 06:06:55 +09:00
parent 958768ccfe
commit 2ee3ec8b7a
2 changed files with 19 additions and 1 deletions

View file

@ -626,9 +626,24 @@ 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)""")
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) self._remNotes(ids)
# tags # tags
self.tags.registerNotes() self.tags.registerNotes()

View file

@ -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
################################################## ##################################################