summary refs log tree commit diff
path: root/synapse/storage/state.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-03-20 16:23:01 +0000
committerErik Johnston <erik@matrix.org>2015-03-20 16:23:01 +0000
commit4848fdbf59b7e4c28baf86179cfd753e433f4d3f (patch)
tree91c2bd508fde6087bad90ce3c79be3f20b40d21e /synapse/storage/state.py
parentAdd the tiniest of tiny one-element caches to get_room_events_max_id() as it'... (diff)
parentPEP8 (diff)
downloadsynapse-4848fdbf59b7e4c28baf86179cfd753e433f4d3f.tar.xz
Merge pull request #113 from matrix-org/store_rearrangement
Store rearrangement
Diffstat (limited to 'synapse/storage/state.py')
-rw-r--r--synapse/storage/state.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/synapse/storage/state.py b/synapse/storage/state.py
index 456e4bd45d..58dbf2802b 100644
--- a/synapse/storage/state.py
+++ b/synapse/storage/state.py
@@ -15,6 +15,8 @@
 
 from ._base import SQLBaseStore
 
+from twisted.internet import defer
+
 import logging
 
 logger = logging.getLogger(__name__)
@@ -122,3 +124,33 @@ class StateStore(SQLBaseStore):
             },
             or_replace=True,
         )
+
+    @defer.inlineCallbacks
+    def get_current_state(self, room_id, event_type=None, state_key=""):
+        del_sql = (
+            "SELECT event_id FROM redactions WHERE redacts = e.event_id "
+            "LIMIT 1"
+        )
+
+        sql = (
+            "SELECT e.*, (%(redacted)s) AS redacted FROM events as e "
+            "INNER JOIN current_state_events as c ON e.event_id = c.event_id "
+            "INNER JOIN state_events as s ON e.event_id = s.event_id "
+            "WHERE c.room_id = ? "
+        ) % {
+            "redacted": del_sql,
+        }
+
+        if event_type and state_key is not None:
+            sql += " AND s.type = ? AND s.state_key = ? "
+            args = (room_id, event_type, state_key)
+        elif event_type:
+            sql += " AND s.type = ?"
+            args = (room_id, event_type)
+        else:
+            args = (room_id, )
+
+        results = yield self._execute_and_decode("get_current_state", sql, *args)
+
+        events = yield self._parse_events(results)
+        defer.returnValue(events)