From 288434178a4e89f86b9740cfe77a4dc0ce9e45f7 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Wed, 19 Oct 2016 02:14:46 -0300 Subject: [bug] total number of documents Parsing from metadata we can store the total of docs and handle it for the doc parser in order to be able to keep consistent events info. --- client/src/leap/soledad/client/http_target/fetch.py | 4 ++-- client/src/leap/soledad/client/http_target/fetch_protocol.py | 4 +++- testing/tests/sync/test_sync_target.py | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/client/src/leap/soledad/client/http_target/fetch.py b/client/src/leap/soledad/client/http_target/fetch.py index 036b5b21..bbc743e1 100644 --- a/client/src/leap/soledad/client/http_target/fetch.py +++ b/client/src/leap/soledad/client/http_target/fetch.py @@ -97,7 +97,7 @@ class HTTPDocFetcher(object): body_reader=body_reader) @defer.inlineCallbacks - def _doc_parser(self, doc_info, content): + def _doc_parser(self, doc_info, content, total): """ Insert a received document into the local replica. @@ -127,7 +127,7 @@ class HTTPDocFetcher(object): doc, doc_info['gen'], doc_info['trans_id']) self._received_docs += 1 user_data = {'uuid': self.uuid, 'userid': self.userid} - _emit_receive_status(user_data, self._received_docs, total=1000000) + _emit_receive_status(user_data, self._received_docs, total=total) def _parse_metadata(self, metadata): """ diff --git a/client/src/leap/soledad/client/http_target/fetch_protocol.py b/client/src/leap/soledad/client/http_target/fetch_protocol.py index 29801819..4290785d 100644 --- a/client/src/leap/soledad/client/http_target/fetch_protocol.py +++ b/client/src/leap/soledad/client/http_target/fetch_protocol.py @@ -113,11 +113,13 @@ class DocStreamReceiver(ReadBodyProtocol): elif self._line == 1: self.metadata = line assert 'error' not in self.metadata + self.total = json.loads(line).get('number_of_changes', -1) elif (self._line % 2) == 0: self.current_doc = json.loads(line) assert 'error' not in self.current_doc else: - self._doc_reader(self.current_doc, line.strip() or None) + self._doc_reader( + self.current_doc, line.strip() or None, self.total) def finish(self): """ diff --git a/testing/tests/sync/test_sync_target.py b/testing/tests/sync/test_sync_target.py index ef034142..17223606 100644 --- a/testing/tests/sync/test_sync_target.py +++ b/testing/tests/sync/test_sync_target.py @@ -63,7 +63,7 @@ class TestSoledadParseReceivedDocResponse(unittest.TestCase): """ def parse(self, stream): - parser = DocStreamReceiver(None, None, lambda x, y: 42) + parser = DocStreamReceiver(None, None, lambda *_: 42) parser.dataReceived(stream) parser.finish() -- cgit v1.2.3