summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Shyba <victor1984@riseup.net>2016-10-19 02:14:46 -0300
committerVictor Shyba <victor1984@riseup.net>2016-11-18 15:55:52 -0300
commitb301f465e50d79f3071fefa0d7675210fe5a733c (patch)
treeef6fc6311d4dd739e6d6defbea2fa2ca51baabd5
parentd81b73b82d9cd3d5a778c9bf5f06f29ecd79727c (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()