summary refs log tree commit diff
path: root/synapse/handlers/device.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2017-02-02 14:27:19 +0000
committerErik Johnston <erik@matrix.org>2017-02-02 14:27:19 +0000
commit46ecd9fd6d4ea2786cde0f2576aa28421be40047 (patch)
tree6d535df209540747c41c155b64a264754f643cce /synapse/handlers/device.py
parentMerge pull request #1875 from matrix-org/erikj/fix_email_push (diff)
downloadsynapse-46ecd9fd6d4ea2786cde0f2576aa28421be40047.tar.xz
Use stream_ordering_to_exterm for /keys/changes
Diffstat (limited to 'synapse/handlers/device.py')
-rw-r--r--synapse/handlers/device.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/synapse/handlers/device.py b/synapse/handlers/device.py
index 815410969c..6c1b945ff3 100644
--- a/synapse/handlers/device.py
+++ b/synapse/handlers/device.py
@@ -17,7 +17,7 @@ from synapse.api import errors
 from synapse.api.constants import EventTypes
 from synapse.util import stringutils
 from synapse.util.async import Linearizer
-from synapse.types import get_domain_from_id
+from synapse.types import get_domain_from_id, RoomStreamToken
 from twisted.internet import defer
 from ._base import BaseHandler
 
@@ -243,15 +243,15 @@ class DeviceHandler(BaseHandler):
 
         possibly_changed = set(changed)
         for room_id in rooms_changed:
-            # Fetch (an approximation) of the current state at the time.
-            event_rows, token = yield self.store.get_recent_event_ids_for_room(
-                room_id, end_token=from_token.room_key, limit=1,
-            )
+            # Fetch  the current state at the time.
+            stream_ordering = RoomStreamToken.parse_stream_token(from_token.room_key)
 
-            if event_rows:
-                last_event_id = event_rows[-1]["event_id"]
-                prev_state_ids = yield self.store.get_state_ids_for_event(last_event_id)
-            else:
+            try:
+                event_ids = yield self.store.get_forward_extremeties_for_room(
+                    room_id, stream_ordering=stream_ordering
+                )
+                prev_state_ids = yield self.store.get_state_ids_for_events(event_ids)
+            except:
                 prev_state_ids = {}
 
             current_state_ids = yield self.state.get_current_state_ids(room_id)