summary refs log tree commit diff
path: root/synapse/storage/state.py
diff options
context:
space:
mode:
authorErik Johnston <erikj@jki.re>2017-06-07 14:01:06 +0100
committerGitHub <noreply@github.com>2017-06-07 14:01:06 +0100
commita053ff397946ed6184e56f37013d0fa9d379d2ff (patch)
treeff1144dbe7bfc0dd281fdc9cf29cfa77bae0054a /synapse/storage/state.py
parentAdd some logging to user directory (diff)
parentComments (diff)
downloadsynapse-a053ff397946ed6184e56f37013d0fa9d379d2ff.tar.xz
Merge pull request #2248 from matrix-org/erikj/state_fixup
Faster cache for get_joined_hosts
Diffstat (limited to 'synapse/storage/state.py')
-rw-r--r--synapse/storage/state.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/synapse/storage/state.py b/synapse/storage/state.py
index a7c3d401d4..c3eecbe824 100644
--- a/synapse/storage/state.py
+++ b/synapse/storage/state.py
@@ -98,6 +98,45 @@ class StateStore(SQLBaseStore):
             _get_current_state_ids_txn,
         )
 
+    def get_state_group_delta(self, state_group):
+        """Given a state group try to return a previous group and a delta between
+        the old and the new.
+
+        Returns:
+            (prev_group, delta_ids), where both may be None.
+        """
+        def _get_state_group_delta_txn(txn):
+            prev_group = self._simple_select_one_onecol_txn(
+                txn,
+                table="state_group_edges",
+                keyvalues={
+                    "state_group": state_group,
+                },
+                retcol="prev_state_group",
+                allow_none=True,
+            )
+
+            if not prev_group:
+                return None, None
+
+            delta_ids = self._simple_select_list_txn(
+                txn,
+                table="state_groups_state",
+                keyvalues={
+                    "state_group": state_group,
+                },
+                retcols=("type", "state_key", "event_id",)
+            )
+
+            return prev_group, {
+                (row["type"], row["state_key"]): row["event_id"]
+                for row in delta_ids
+            }
+        return self.runInteraction(
+            "get_state_group_delta",
+            _get_state_group_delta_txn,
+        )
+
     @defer.inlineCallbacks
     def get_state_groups_ids(self, room_id, event_ids):
         if not event_ids: