summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorVictor Shyba <victor1984@riseup.net>2016-10-29 23:26:36 -0300
committerVictor Shyba <victor1984@riseup.net>2016-11-18 15:55:52 -0300
commit2a44139fe023de83563614a95e17ef3e8e5616bd (patch)
tree735501f396bc82762c387cd210b4301304ed4eeb /server
parente60af207fb9bb10f8556d90dc30e369590945693 (diff)
[refactor] simplify server insert
Moved out magic numbers into a constant and simplified logic during doc upload.
Diffstat (limited to 'server')
-rw-r--r--server/src/leap/soledad/server/sync.py21
1 files changed, 5 insertions, 16 deletions
diff --git a/server/src/leap/soledad/server/sync.py b/server/src/leap/soledad/server/sync.py
index 8a05b91f..d43fc822 100644
--- a/server/src/leap/soledad/server/sync.py
+++ b/server/src/leap/soledad/server/sync.py
@@ -29,6 +29,7 @@ from leap.soledad.common.document import ServerDocument
MAX_REQUEST_SIZE = 6000 # in Mb
MAX_ENTRY_SIZE = 200 # in Mb
+ENTRY_CACHE_SIZE = 8192 * 1024
class SyncExchange(sync.SyncExchange):
@@ -242,22 +243,10 @@ class SyncResource(http_app.SyncResource):
:param doc_idx: The index of the current document.
:type doc_idx: int
"""
- doc = ServerDocument(id, rev)
- doc._json = content
- if (len(content or '') > (8192 * 1024) / 4) or number_of_docs < 4:
- self.sync_exch.batched_insert_from_source(self._staging,
- self._sync_id)
- self._staging = []
- self._staging_size = 0
- self.sync_exch.insert_doc_from_source(
- doc, gen, trans_id,
- number_of_docs=number_of_docs,
- doc_idx=doc_idx,
- sync_id=self._sync_id)
- else:
- self._staging_size += len(content or '')
- self._staging.append((doc, gen, trans_id, number_of_docs, doc_idx))
- if self._staging_size > 8192 * 1024 or doc_idx == number_of_docs:
+ doc = ServerDocument(id, rev, json=content)
+ self._staging_size += len(content or '')
+ self._staging.append((doc, gen, trans_id, number_of_docs, doc_idx))
+ if self._staging_size > ENTRY_CACHE_SIZE or doc_idx == number_of_docs:
self.sync_exch.batched_insert_from_source(self._staging,
self._sync_id)
self._staging = []