From 632cd2414a47bc7f471d8f501ab6250293aedf51 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Thu, 17 Nov 2016 00:38:55 -0300 Subject: [bug] include_deleted=True on sync Also refactored tests and code to stop relying on old parameters which included docs instead of get_doc calls. --- client/src/leap/soledad/client/http_target/send.py | 14 +++++--------- client/src/leap/soledad/client/sync.py | 15 ++++++++++----- 2 files changed, 15 insertions(+), 14 deletions(-) (limited to 'client/src') diff --git a/client/src/leap/soledad/client/http_target/send.py b/client/src/leap/soledad/client/http_target/send.py index ae0b126f..c15488a0 100644 --- a/client/src/leap/soledad/client/http_target/send.py +++ b/client/src/leap/soledad/client/http_target/send.py @@ -86,21 +86,17 @@ class HTTPDocSender(object): @defer.inlineCallbacks def _prepare_one_doc(self, entry, body, idx, total): - get_doc, gen, trans_id = entry - doc, content = yield self._encrypt_doc(get_doc) + get_doc_call, gen, trans_id = entry + doc, content = yield self._encrypt_doc(get_doc_call) body.insert_info( id=doc.doc_id, rev=doc.rev, content=content, gen=gen, trans_id=trans_id, number_of_docs=total, doc_idx=idx) @defer.inlineCallbacks - def _encrypt_doc(self, get_doc): - if type(get_doc) == tuple: - f, args = get_doc - doc = yield f(args) - else: - # tests - doc = get_doc + def _encrypt_doc(self, get_doc_call): + f, args, kwargs = get_doc_call + doc = yield f(*args, **kwargs) if doc.is_tombstone(): defer.returnValue((doc, None)) else: diff --git a/client/src/leap/soledad/client/sync.py b/client/src/leap/soledad/client/sync.py index 6bd58f8f..70c841d6 100644 --- a/client/src/leap/soledad/client/sync.py +++ b/client/src/leap/soledad/client/sync.py @@ -141,11 +141,7 @@ class SoledadSynchronizer(Synchronizer): self.sync_phase[0] += 1 # -------------------------------------------------------------------- - ids_sent = [doc_id for doc_id, _, _ in changes] - docs_by_generation = [] - for doc_id, gen, trans in changes: - get_doc = (self.source.get_doc, doc_id) - docs_by_generation.append((get_doc, gen, trans)) + docs_by_generation = self._docs_by_gen_from_changes(changes) # exchange documents and try to insert the returned ones with # the target, return target synced-up-to gen. @@ -153,6 +149,7 @@ class SoledadSynchronizer(Synchronizer): docs_by_generation, self.source._replica_uid, target_last_known_gen, target_last_known_trans_id, self._insert_doc_from_target, ensure_callback=ensure_callback) + ids_sent = [doc_id for doc_id, _, _ in changes] logger.debug("target gen after sync: %d" % new_gen) logger.debug("target trans_id after sync: %s" % new_trans_id) if hasattr(self.source, 'commit'): # sqlcipher backend speed up @@ -185,6 +182,14 @@ class SoledadSynchronizer(Synchronizer): defer.returnValue(my_gen) + def _docs_by_gen_from_changes(self, changes): + docs_by_generation = [] + kwargs = {'include_deleted': True} + for doc_id, gen, trans in changes: + get_doc = (self.source.get_doc, (doc_id,), kwargs) + docs_by_generation.append((get_doc, gen, trans)) + return docs_by_generation + def complete_sync(self): """ Last stage of the synchronization: -- cgit v1.2.3