From fd99f15f1da1bed6c223876b7e2e72477ca8b2ee Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Wed, 20 Sep 2017 03:00:20 -0300 Subject: [feature] persist pending_download remote listing -- Related: #8822 --- src/leap/soledad/client/_db/blobs.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/leap') diff --git a/src/leap/soledad/client/_db/blobs.py b/src/leap/soledad/client/_db/blobs.py index 4b90f8f2..e23b1cf9 100644 --- a/src/leap/soledad/client/_db/blobs.py +++ b/src/leap/soledad/client/_db/blobs.py @@ -274,6 +274,15 @@ class BlobManager(object): def local_list(self, namespace='', sync_status=None): return self.local.list(namespace, sync_status) + @defer.inlineCallbacks + def refresh_sync_status_from_server(self): + d1 = self.remote_list() + d2 = self.local_list() + remote_list, local_list = yield defer.gatherResults([d1, d2]) + pending_download_ids = tuple(set(remote_list) - set(local_list)) + yield self.local.update_batch_sync_status( + pending_download_ids, sync_status=SyncStatus.PENDING_DOWNLOAD) + @defer.inlineCallbacks def send_missing(self, namespace=''): """ @@ -590,6 +599,17 @@ class SQLiteBlobBackend(object): values = (sync_status, blob_id,) return self.dbpool.runQuery(query, values) + def update_batch_sync_status(self, blob_id_list, sync_status, + namespace=''): + insert = 'INSERT INTO blobs (blob_id, namespace, payload, sync_status)' + first_blob_id, blob_id_list = blob_id_list[0], blob_id_list[1:] + insert += ' VALUES (?, ?, zeroblob(0), ?)' + values = (first_blob_id, namespace, sync_status) + for blob_id in blob_id_list: + insert += ', (?, ?, zeroblob(0), ?)' + values += (blob_id, namespace, sync_status) + return self.dbpool.runQuery(insert, values) + def increment_retries(self, blob_id): query = 'update blobs set retries = retries + 1 where blob_id = ?' return self.dbpool.runQuery(query, (blob_id,)) -- cgit v1.2.3