summary refs log tree commit diff
path: root/synapse/storage/stream.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2014-08-15 13:58:28 +0100
committerErik Johnston <erik@matrix.org>2014-08-15 13:58:28 +0100
commit114984a2361ee41005a769f6dc127c470ee08aee (patch)
treea295be465b71cbc048260b714e9fd042b4accb45 /synapse/storage/stream.py
parentMerge branch 'master' of github.com:matrix-org/synapse into sql_refactor (diff)
downloadsynapse-114984a2361ee41005a769f6dc127c470ee08aee.tar.xz
Start chagning the events stream to work with the new DB schema
Diffstat (limited to 'synapse/storage/stream.py')
-rw-r--r--synapse/storage/stream.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/synapse/storage/stream.py b/synapse/storage/stream.py
index 9937239c22..c5c3770a40 100644
--- a/synapse/storage/stream.py
+++ b/synapse/storage/stream.py
@@ -34,6 +34,7 @@ class StreamStore(SQLBaseStore):
     @defer.inlineCallbacks
     def get_room_events_stream(self, user_id, from_key, to_key, room_id,
                                limit=0, with_feedback=False):
+        # TODO (erikj): Handle compressed feedback
 
         current_room_membership_sql = (
             "SELECT m.room_id FROM room_memberships as m "
@@ -69,3 +70,33 @@ class StreamStore(SQLBaseStore):
         )
 
         defer.returnValue([self._parse_event_from_row(r) for r in rows])
+
+    @defer.inlineCallbacks
+    def get_recent_events_for_room(self, room_id, limit, with_feedback=False):
+        # TODO (erikj): Handle compressed feedback
+
+        sql = (
+            "SELECT * FROM events WHERE room_id = ? "
+            "ORDER BY ordering DESC LIMIT ? "
+        )
+
+        rows = yield self._execute_and_decode(
+            sql,
+            room_id, limit
+        )
+
+        rows.reverse()  # As we selected with reverse ordering
+
+        defer.returnValue([self._parse_event_from_row(r) for r in rows])
+
+    @defer.inlineCallbacks
+    def get_room_events_max_id(self):
+        res = yield self._execute_and_decode(
+            "SELECT MAX(ordering) as m FROM events"
+        )
+
+        if not res:
+            defer.returnValue(0)
+            return
+
+        defer.returnValue(res[0]["m"])