summary refs log tree commit diff
path: root/synapse/storage/state.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-06-03 17:20:33 +0100
committerErik Johnston <erik@matrix.org>2015-06-03 17:20:33 +0100
commit13ed3b99856a104e172b0e5bc0996c39242f0224 (patch)
tree1c930ae2488e1298c8e94652cd7d2f701d7a6c37 /synapse/storage/state.py
parentMerge pull request #177 from matrix-org/erikj/content_repo_http_client (diff)
parentAdd cache to get_state_groups (diff)
downloadsynapse-13ed3b99856a104e172b0e5bc0996c39242f0224.tar.xz
Merge pull request #178 from matrix-org/erikj/cache_state_groups
Add cache to get_state_groups.
Diffstat (limited to 'synapse/storage/state.py')
-rw-r--r--synapse/storage/state.py20
1 files changed, 12 insertions, 8 deletions
diff --git a/synapse/storage/state.py b/synapse/storage/state.py
index b24de34f23..f2b17f29ea 100644
--- a/synapse/storage/state.py
+++ b/synapse/storage/state.py
@@ -81,19 +81,23 @@ class StateStore(SQLBaseStore):
             f,
         )
 
-        @defer.inlineCallbacks
-        def c(vals):
-            vals[:] = yield self._get_events(vals, get_prev_content=False)
-
-        yield defer.gatherResults(
+        state_list = yield defer.gatherResults(
             [
-                c(vals)
-                for vals in states.values()
+                self._fetch_events_for_group(group, vals)
+                for group, vals in states.items()
             ],
             consumeErrors=True,
         )
 
-        defer.returnValue(states)
+        defer.returnValue(dict(state_list))
+
+    @cached(num_args=1)
+    def _fetch_events_for_group(self, state_group, events):
+        return self._get_events(
+            events, get_prev_content=False
+        ).addCallback(
+            lambda evs: (state_group, evs)
+        )
 
     def _store_state_groups_txn(self, txn, event, context):
         if context.current_state is None: