summaryrefslogtreecommitdiff
path: root/src/leap/soledad/client/_db
diff options
context:
space:
mode:
authorVictor Shyba <victor1984@riseup.net>2017-11-11 00:37:01 -0300
committerVictor Shyba <victor1984@riseup.net>2017-11-13 18:17:15 -0300
commit8f3fdc2f9c3d4360669c2c7fd89dbd95e0f8dd22 (patch)
tree7d711a51d896811fe6309eb5a368ed468276a6d8 /src/leap/soledad/client/_db
parent914579325d242e2643a964bbf1b271435b5c66cc (diff)
[feature] apply deletions from server
Sync method to propagate deletions in batch locally. -- Resolves: #8961
Diffstat (limited to 'src/leap/soledad/client/_db')
-rw-r--r--src/leap/soledad/client/_db/blobs/sql.py7
-rw-r--r--src/leap/soledad/client/_db/blobs/sync.py7
2 files changed, 14 insertions, 0 deletions
diff --git a/src/leap/soledad/client/_db/blobs/sql.py b/src/leap/soledad/client/_db/blobs/sql.py
index c5b0b64b..5337ab87 100644
--- a/src/leap/soledad/client/_db/blobs/sql.py
+++ b/src/leap/soledad/client/_db/blobs/sql.py
@@ -190,6 +190,13 @@ class SQLiteBlobBackend(object):
query = 'DELETE FROM blobs WHERE blob_id = ? AND namespace = ?'
return self.dbpool.runQuery(query, (blob_id, namespace,))
+ def batch_delete(self, blob_id_list, namespace=''):
+ query = 'DELETE FROM blobs WHERE blob_id IN '
+ size = len(blob_id_list)
+ query += ('(%s)' % ', '.join(['?' for _ in range(size)]))
+ values = tuple(blob_id_list)
+ return self.dbpool.runQuery(query, values)
+
def _init_tables(conn):
# unified init for running under the same lock
diff --git a/src/leap/soledad/client/_db/blobs/sync.py b/src/leap/soledad/client/_db/blobs/sync.py
index bfdc5fbe..bdfbb983 100644
--- a/src/leap/soledad/client/_db/blobs/sync.py
+++ b/src/leap/soledad/client/_db/blobs/sync.py
@@ -73,6 +73,12 @@ class BlobsSynchronizer(object):
namespace=namespace)
@defer.inlineCallbacks
+ def _apply_deletions_from_server(self, namespace=''):
+ remote_deletions = self.remote_list(namespace=namespace, deleted=True)
+ remote_deletions = yield remote_deletions
+ yield self.local.batch_delete(remote_deletions)
+
+ @defer.inlineCallbacks
def send_missing(self, namespace=''):
"""
Compare local and remote blobs and send what's missing in server.
@@ -131,6 +137,7 @@ class BlobsSynchronizer(object):
@defer.inlineCallbacks
def sync(self, namespace=''):
try:
+ yield self._apply_deletions_from_server(namespace)
yield self.refresh_sync_status_from_server(namespace)
yield self.fetch_missing(namespace)
yield self.send_missing(namespace)