don't delete orphaned notes on sync

Fields are synced later, and they may prevent a note from becoming orphaned
This commit is contained in:
Damien Elmes 2012-07-04 22:41:21 +09:00
parent 74af374720
commit c5abb535ed
2 changed files with 4 additions and 2 deletions

View file

@ -394,7 +394,7 @@ insert into cards values (?,?,?,?,?,?,0,0,?,0,0,0,0,0,0,0,0,"")""",
def cardCount(self): def cardCount(self):
return self.db.scalar("select count() from cards") return self.db.scalar("select count() from cards")
def remCards(self, ids): def remCards(self, ids, notes=True):
"Bulk delete cards by ID." "Bulk delete cards by ID."
if not ids: if not ids:
return 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 cards where id in "+sids)
self.db.execute("delete from revlog where cid in "+sids) self.db.execute("delete from revlog where cid in "+sids)
# then notes # then notes
if not notes:
return
nids = self.db.list(""" nids = self.db.list("""
select id from notes where id in %s and id not in (select nid from cards)""" % select id from notes where id in %s and id not in (select nid from cards)""" %
ids2str(nids)) ids2str(nids))

View file

@ -311,7 +311,7 @@ from notes where %s""" % d)
# notes first, so we don't end up with duplicate graves # notes first, so we don't end up with duplicate graves
self.col._remNotes(graves['notes']) self.col._remNotes(graves['notes'])
# then cards # then cards
self.col.remCards(graves['cards']) self.col.remCards(graves['cards'], notes=False)
# and decks # and decks
for oid in graves['decks']: for oid in graves['decks']:
self.col.decks.rem(oid, childrenToo=False) self.col.decks.rem(oid, childrenToo=False)