summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Shyba <victor.shyba@gmail.com>2016-08-11 11:34:47 -0300
committerdrebs <drebs@leap.se>2016-12-12 09:11:58 -0200
commitffe15f154541b6f929c569caf07560d117ad5efa (patch)
treeb83b78dd5a59320abe04515732d9ccdd773f539c
parent81f97ec532a13dc57bf23a44dab3d44d12cc2ba4 (diff)
[feature] use transactions on sync
We were using 1 transaction per doc, which is bad. Reference: http://stackoverflow.com/questions/1711631/improve-insert-per-second-performance-of-sqlite Code now uses 1 transaction for the whole sync.
-rw-r--r--client/src/leap/soledad/client/sqlcipher.py3
-rw-r--r--client/src/leap/soledad/client/sync.py1
-rw-r--r--common/src/leap/soledad/common/l2db/backends/sqlite_backend.py11
3 files changed, 9 insertions, 6 deletions
diff --git a/client/src/leap/soledad/client/sqlcipher.py b/client/src/leap/soledad/client/sqlcipher.py
index 3921c323..b198607d 100644
--- a/client/src/leap/soledad/client/sqlcipher.py
+++ b/client/src/leap/soledad/client/sqlcipher.py
@@ -458,6 +458,9 @@ class SQLCipherU1DBSync(SQLCipherDatabase):
if DO_STATS:
self.sync_phase = None
+ def commit(self):
+ self._db_handle.commit()
+
@property
def _replica_uid(self):
return str(self.__replica_uid)
diff --git a/client/src/leap/soledad/client/sync.py b/client/src/leap/soledad/client/sync.py
index 7ed5f693..8303f65d 100644
--- a/client/src/leap/soledad/client/sync.py
+++ b/client/src/leap/soledad/client/sync.py
@@ -176,6 +176,7 @@ class SoledadSynchronizer(Synchronizer):
defer_decryption=defer_decryption)
logger.debug("target gen after sync: %d" % new_gen)
logger.debug("target trans_id after sync: %s" % new_trans_id)
+ self.source.commit() # sync worked, commit
info = {
"target_replica_uid": self.target_replica_uid,
"new_gen": new_gen,
diff --git a/common/src/leap/soledad/common/l2db/backends/sqlite_backend.py b/common/src/leap/soledad/common/l2db/backends/sqlite_backend.py
index d73c0d16..295f3132 100644
--- a/common/src/leap/soledad/common/l2db/backends/sqlite_backend.py
+++ b/common/src/leap/soledad/common/l2db/backends/sqlite_backend.py
@@ -505,12 +505,11 @@ class SQLiteDatabase(CommonBackend):
def _put_doc_if_newer(self, doc, save_conflict, replica_uid=None,
replica_gen=None, replica_trans_id=None):
- with self._db_handle:
- return super(SQLiteDatabase, self)._put_doc_if_newer(
- doc,
- save_conflict=save_conflict,
- replica_uid=replica_uid, replica_gen=replica_gen,
- replica_trans_id=replica_trans_id)
+ return super(SQLiteDatabase, self)._put_doc_if_newer(
+ doc,
+ save_conflict=save_conflict,
+ replica_uid=replica_uid, replica_gen=replica_gen,
+ replica_trans_id=replica_trans_id)
def _add_conflict(self, c, doc_id, my_doc_rev, my_content):
c.execute("INSERT INTO conflicts VALUES (?, ?, ?)",