summary refs log tree commit diff
diff options
context:
space:
mode:
authorLuke Barnard <lukeb@openmarket.com>2017-04-12 14:36:20 +0100
committerLuke Barnard <lukeb@openmarket.com>2017-04-12 14:36:20 +0100
commitb9557064bf6003a666b8fb6813dd3618fe9e48b4 (patch)
treece2cee50fe81f42be61fcc6591f7b337c13580bb
parentMore null-guard changes (diff)
downloadsynapse-b9557064bf6003a666b8fb6813dd3618fe9e48b4.tar.xz
Simplify is_event_after logic
-rw-r--r--synapse/handlers/read_marker.py5
-rw-r--r--synapse/storage/events.py13
2 files changed, 6 insertions, 12 deletions
diff --git a/synapse/handlers/read_marker.py b/synapse/handlers/read_marker.py
index 800240b8a9..3f46a16b90 100644
--- a/synapse/handlers/read_marker.py
+++ b/synapse/handlers/read_marker.py
@@ -48,9 +48,10 @@ class ReadMarkerHandler(BaseHandler):
             should_update = True
 
             if existing_read_marker:
+                # Only update if the new marker is ahead in the stream
                 should_update = yield self.store.is_event_after(
-                    existing_read_marker['marker'],
-                    event_id
+                    event_id,
+                    existing_read_marker['marker']
                 )
 
             if should_update:
diff --git a/synapse/storage/events.py b/synapse/storage/events.py
index 702bd64b2e..221cb563d8 100644
--- a/synapse/storage/events.py
+++ b/synapse/storage/events.py
@@ -2161,18 +2161,11 @@ class EventsStore(SQLBaseStore):
 
     @defer.inlineCallbacks
     def is_event_after(self, event_id1, event_id2):
-        is_after = True
-
+        """Returns True if event_id1 is after event_id2 in the stream
+        """
         to_1, so_1 = yield self._get_event_ordering(event_id1)
         to_2, so_2 = yield self._get_event_ordering(event_id2)
-
-        # Prevent updating if the existing marker is ahead in the stream
-        if to_1 > to_2:
-            is_after = False
-        elif to_1 == to_2 and so_1 >= so_2:
-            is_after = False
-
-        defer.returnValue(is_after)
+        defer.returnValue(to_1 > to_2 and so_1 > so_2)
 
     @defer.inlineCallbacks
     def _get_event_ordering(self, event_id):