summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/src/leap/soledad/common/couch.py2
-rw-r--r--server/src/leap/soledad/server/caching.py4
-rw-r--r--server/src/leap/soledad/server/sync.py5
3 files changed, 8 insertions, 3 deletions
diff --git a/common/src/leap/soledad/common/couch.py b/common/src/leap/soledad/common/couch.py
index 83f542ab..809af05d 100644
--- a/common/src/leap/soledad/common/couch.py
+++ b/common/src/leap/soledad/common/couch.py
@@ -527,6 +527,7 @@ class CouchDatabase(CommonBackend):
try:
# grab replica_uid from server
doc = self._database['u1db_config']
+ self.cache[self._url] = doc
self._real_replica_uid = doc['replica_uid']
return self._real_replica_uid
except ResourceNotFound:
@@ -1154,6 +1155,7 @@ class CouchDatabase(CommonBackend):
doc['generation'] = other_generation
doc['transaction_id'] = other_transaction_id
self._database.save(doc)
+ self.cache[other_replica_uid] = (other_generation, other_transaction_id)
def _force_doc_sync_conflict(self, doc):
"""
diff --git a/server/src/leap/soledad/server/caching.py b/server/src/leap/soledad/server/caching.py
index cd5d8dd4..9a049a39 100644
--- a/server/src/leap/soledad/server/caching.py
+++ b/server/src/leap/soledad/server/caching.py
@@ -28,5 +28,5 @@ def setup_caching():
_cache_manager = setup_caching()
-def get_cache_for(key):
- return _cache_manager.get_cache(key)
+def get_cache_for(key, expire=3600):
+ return _cache_manager.get_cache(key, expire=expire)
diff --git a/server/src/leap/soledad/server/sync.py b/server/src/leap/soledad/server/sync.py
index 262b6769..e4fd1260 100644
--- a/server/src/leap/soledad/server/sync.py
+++ b/server/src/leap/soledad/server/sync.py
@@ -185,12 +185,15 @@ class SyncResource(http_app.SyncResource):
:type ensure: bool
"""
# create or open the database
+ cache = get_cache_for('db-' + sync_id + self.dbname)
if ensure:
db, self.replica_uid = self.state.ensure_database(self.dbname)
+ elif cache and 'instance' in cache:
+ db = cache['instance']
else:
db = self.state.open_database(self.dbname)
- cache = get_cache_for('db-' + sync_id + db.replica_uid)
db._cache = cache
+ cache['instance'] = db
# validate the information the client has about server replica
db.validate_gen_and_trans_id(
last_known_generation, last_known_trans_id)