mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
only use deletion log when necessary
This commit is contained in:
parent
ec8c720048
commit
0af03a6a8a
2 changed files with 17 additions and 2 deletions
13
anki/deck.py
13
anki/deck.py
|
@ -215,6 +215,15 @@ qconf=?, conf=?, data=?""",
|
|||
##########################################################################
|
||||
|
||||
def _logDels(self, ids, type):
|
||||
if not self.syncingEnabled():
|
||||
# no deletion log required if deck not syncable
|
||||
return
|
||||
# limit ids to those created prior to last sync
|
||||
tbl = "cards" if type == DEL_CARD else "facts"
|
||||
ids = self.db.list(
|
||||
"select id from %s where crt < ? and id in %s" % (
|
||||
tbl, ids2str(ids)), self.lastSync)
|
||||
# log
|
||||
self.db.executemany("insert into graves values (%d, ?, %d)" % (
|
||||
intTime(), type), ([x] for x in ids))
|
||||
|
||||
|
@ -254,9 +263,9 @@ qconf=?, conf=?, data=?""",
|
|||
if not ids:
|
||||
return
|
||||
strids = ids2str(ids)
|
||||
self._logDels(ids, DEL_FACT)
|
||||
self.db.execute("delete from facts where id in %s" % strids)
|
||||
self.db.execute("delete from fsums where fid in %s" % strids)
|
||||
self._logDels(ids, DEL_FACT)
|
||||
|
||||
# Card creation
|
||||
##########################################################################
|
||||
|
@ -349,9 +358,9 @@ qconf=?, conf=?, data=?""",
|
|||
sids = ids2str(ids)
|
||||
fids = self.db.list("select fid from cards where id in "+sids)
|
||||
# remove cards
|
||||
self._logDels(ids, DEL_CARD)
|
||||
self.db.execute("delete from cards where id in "+sids)
|
||||
self.db.execute("delete from revlog where cid in "+sids)
|
||||
self._logDels(ids, DEL_CARD)
|
||||
# then facts
|
||||
fids = self.db.list("""
|
||||
select id from facts where id in %s and id not in (select fid from cards)""" %
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
# coding: utf-8
|
||||
|
||||
import time
|
||||
from anki.db import DB
|
||||
from anki.consts import *
|
||||
from tests.shared import getEmptyDeck
|
||||
|
@ -63,13 +64,18 @@ def test_delete():
|
|||
assert deck.db.scalar("select count() from cards") == 0
|
||||
assert deck.db.scalar("select count() from fsums") == 0
|
||||
assert deck.db.scalar("select count() from revlog") == 0
|
||||
assert deck.db.scalar("select count() from graves") == 0
|
||||
# add the fact back
|
||||
deck.addFact(f)
|
||||
assert deck.cardCount() == 1
|
||||
cid = f.cards()[0].id
|
||||
# delete again, this time with syncing enabled
|
||||
deck.syncName = "abc"
|
||||
deck.lastSync = time.time()
|
||||
deck.delCards([cid])
|
||||
assert deck.cardCount() == 0
|
||||
assert deck.factCount() == 0
|
||||
assert deck.db.scalar("select count() from graves") != 0
|
||||
|
||||
def test_misc():
|
||||
d = getEmptyDeck()
|
||||
|
|
Loading…
Reference in a new issue