summary refs log tree commit diff
path: root/synapse/storage/data_stores/main/state.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2019-10-30 15:12:49 +0000
committerErik Johnston <erik@matrix.org>2019-10-30 15:23:37 +0000
commit7c8c97e635811609c5a7ae4c0bb94e6573c30753 (patch)
tree60827c247fcdecab2225486a14a3122513fde86d /synapse/storage/data_stores/main/state.py
parentMerge pull request #6240 from matrix-org/erikj/split_out_persistence_store (diff)
downloadsynapse-7c8c97e635811609c5a7ae4c0bb94e6573c30753.tar.xz
Split purge API into events vs state
Diffstat (limited to 'synapse/storage/data_stores/main/state.py')
-rw-r--r--synapse/storage/data_stores/main/state.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/synapse/storage/data_stores/main/state.py b/synapse/storage/data_stores/main/state.py
index 9b2207075b..36be8f0a9d 100644
--- a/synapse/storage/data_stores/main/state.py
+++ b/synapse/storage/data_stores/main/state.py
@@ -989,6 +989,29 @@ class StateGroupWorkerStore(
 
         return self.runInteraction("store_state_group", _store_state_group_txn)
 
+    @defer.inlineCallbacks
+    def get_referenced_state_groups(self, state_groups):
+        """Check if the state groups are referenced by events.
+
+        Args:
+            state_groups (Iterable[int])
+
+        Returns:
+            Deferred[set[int]]: The subset of state groups that are
+            referenced.
+        """
+
+        rows = yield self._simple_select_many_batch(
+            table="event_to_state_groups",
+            column="state_group",
+            iterable=state_groups,
+            keyvalues={},
+            retcols=("DISTINCT state_group",),
+            desc="get_referenced_state_groups",
+        )
+
+        return set(row["state_group"] for row in rows)
+
 
 class StateBackgroundUpdateStore(
     StateGroupBackgroundUpdateStore, BackgroundUpdateStore