mirror of
https://github.com/ankitects/anki.git
synced 2025-11-08 21:57:12 -05:00
properly lock the DB
This commit is contained in:
parent
c17758b01c
commit
9226922af8
3 changed files with 10 additions and 4 deletions
|
|
@ -14,9 +14,8 @@ except ImportError:
|
|||
from anki.hooks import runHook
|
||||
|
||||
class DB(object):
|
||||
def __init__(self, path, level="EXCLUSIVE", text=None):
|
||||
self._db = sqlite.connect(
|
||||
path, timeout=0, isolation_level=level)
|
||||
def __init__(self, path, text=None):
|
||||
self._db = sqlite.connect(path, timeout=0, isolation_level=None)
|
||||
if text:
|
||||
self._db.text_factory = text
|
||||
self._path = path
|
||||
|
|
|
|||
|
|
@ -113,9 +113,14 @@ qconf=?, conf=?, data=?""",
|
|||
simplejson.dumps(self.conf), simplejson.dumps(self.data))
|
||||
|
||||
def save(self):
|
||||
"Flush, then commit DB."
|
||||
"Flush, commit DB, and take out another write lock."
|
||||
self.flush()
|
||||
self.db.commit()
|
||||
self.lock()
|
||||
|
||||
def lock(self):
|
||||
self.db.execute("begin exclusive")
|
||||
self.db.execute("update deck set mod=mod")
|
||||
|
||||
def close(self, save=True):
|
||||
"Disconnect from DB."
|
||||
|
|
@ -135,6 +140,7 @@ qconf=?, conf=?, data=?""",
|
|||
|
||||
def rollback(self):
|
||||
self.db.rollback()
|
||||
self.lock()
|
||||
|
||||
def modSchema(self):
|
||||
if not self.schemaDirty():
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ def Deck(path, queue=True):
|
|||
elif create:
|
||||
deck.addModel(BasicModel(deck))
|
||||
deck.save()
|
||||
deck.lock()
|
||||
if not queue:
|
||||
return deck
|
||||
# rebuild queue
|
||||
|
|
|
|||
Loading…
Reference in a new issue