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 15:28:54 +0100
committerErik Johnston <erik@matrix.org>2014-08-15 15:28:54 +0100
commit01f089d9fbb9b89fa143ac44e51529fa8ed7ec12 (patch)
tree1f3544621b65749fd379fbb328a1745d775ef2fa /synapse/storage/stream.py
parentStart chagning the events stream to work with the new DB schema (diff)
downloadsynapse-01f089d9fbb9b89fa143ac44e51529fa8ed7ec12.tar.xz
Correctly return new token when returning events. Serialize events correctly.
Diffstat (limited to 'synapse/storage/stream.py')
-rw-r--r--synapse/storage/stream.py18
1 files changed, 13 insertions, 5 deletions
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):