summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Shyba <victor1984@riseup.net>2016-10-19 02:14:46 -0300
committerdrebs <drebs@leap.se>2016-12-12 09:12:00 -0200
commit288434178a4e89f86b9740cfe77a4dc0ce9e45f7 (patch)
tree783e5d62a48fad4f31782922386bd0ef76c14505
parent8ff1f0b781c49b88da13af390e4d118ad3e77b43 (diff)
[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.
-rw-r--r--client/src/leap/soledad/client/http_target/fetch.py4
-rw-r--r--client/src/leap/soledad/client/http_target/fetch_protocol.py4
-rw-r--r--testing/tests/sync/test_sync_target.py2
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()