summary refs log tree commit diff
path: root/synapse/storage
diff options
context:
space:
mode:
Diffstat (limited to 'synapse/storage')
-rw-r--r--synapse/storage/__init__.py6
-rw-r--r--synapse/storage/stream.py18
2 files changed, 18 insertions, 6 deletions
diff --git a/synapse/storage/__init__.py b/synapse/storage/__init__.py
index 46b9dbcbbf..750e86040e 100644
--- a/synapse/storage/__init__.py
+++ b/synapse/storage/__init__.py
@@ -57,7 +57,8 @@ class DataStore(RoomMemberStore, RoomStore,
         elif event.type == RoomTopicEvent.TYPE:
             yield self._store_room_topic(event)
 
-        yield self._store_event(event)
+        ret = yield self._store_event(event)
+        defer.returnValue(ret)
 
     @defer.inlineCallbacks
     def get_event(self, event_id):
@@ -114,6 +115,9 @@ class DataStore(RoomMemberStore, RoomStore,
                 }
             )
 
+        latest = yield self.get_room_events_max_id()
+        defer.returnValue(latest)
+
     @defer.inlineCallbacks
     def get_current_state(self, room_id, event_type=None, state_key=""):
         sql = (
diff --git a/synapse/storage/stream.py b/synapse/storage/stream.py
index c5c3770a40..1300aee8b0 100644
--- a/synapse/storage/stream.py
+++ b/synapse/storage/stream.py
@@ -43,7 +43,7 @@ class StreamStore(SQLBaseStore):
         )
 
         invites_sql = (
-            "SELECT m.event_id FROM room_membershipas as m "
+            "SELECT m.event_id FROM room_memberships as m "
             "INNER JOIN current_state_events as c ON m.event_id = c.event_id "
             "WHERE m.user_id = ? AND m.membership = ?"
         )
@@ -55,8 +55,9 @@ class StreamStore(SQLBaseStore):
 
         sql = (
             "SELECT * FROM events as e WHERE "
-            "(room_id IN (%(current)s)) OR "
-            "(event_id IN (%(invites)s)) "
+            "((room_id IN (%(current)s)) OR "
+            "(event_id IN (%(invites)s))) "
+            " AND e.ordering > ? AND e.ordering < ? "
             "ORDER BY ordering ASC LIMIT %(limit)d"
         ) % {
             "current": current_room_membership_sql,
@@ -66,10 +67,17 @@ class StreamStore(SQLBaseStore):
 
         rows = yield self._execute_and_decode(
             sql,
-            user_id, user_id, Membership.INVITE
+            user_id, user_id, Membership.INVITE, from_key, to_key
         )
 
-        defer.returnValue([self._parse_event_from_row(r) for r in rows])
+        ret = [self._parse_event_from_row(r) for r in rows]
+
+        if ret:
+            max_id = max([r["ordering"] for r in rows])
+        else:
+            max_id = to_key
+
+        defer.returnValue((ret, max_id))
 
     @defer.inlineCallbacks
     def get_recent_events_for_room(self, room_id, limit, with_feedback=False):