From c5abb535ed79298d26fbf0e1ea986da50ef6bacd Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Wed, 4 Jul 2012 22:41:21 +0900 Subject: [PATCH] don't delete orphaned notes on sync Fields are synced later, and they may prevent a note from becoming orphaned --- anki/collection.py | 4 +++- anki/sync.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/anki/collection.py b/anki/collection.py index c890f3e16..6de0cd01b 100644 --- a/anki/collection.py +++ b/anki/collection.py @@ -394,7 +394,7 @@ insert into cards values (?,?,?,?,?,?,0,0,?,0,0,0,0,0,0,0,0,"")""", def cardCount(self): return self.db.scalar("select count() from cards") - def remCards(self, ids): + def remCards(self, ids, notes=True): "Bulk delete cards by ID." if not ids: return @@ -405,6 +405,8 @@ insert into cards values (?,?,?,?,?,?,0,0,?,0,0,0,0,0,0,0,0,"")""", self.db.execute("delete from cards where id in "+sids) self.db.execute("delete from revlog where cid in "+sids) # then notes + if not notes: + return nids = self.db.list(""" select id from notes where id in %s and id not in (select nid from cards)""" % ids2str(nids)) diff --git a/anki/sync.py b/anki/sync.py index 0251993a4..3aed27092 100644 --- a/anki/sync.py +++ b/anki/sync.py @@ -311,7 +311,7 @@ from notes where %s""" % d) # notes first, so we don't end up with duplicate graves self.col._remNotes(graves['notes']) # then cards - self.col.remCards(graves['cards']) + self.col.remCards(graves['cards'], notes=False) # and decks for oid in graves['decks']: self.col.decks.rem(oid, childrenToo=False)