Simplify is_event_after logic
parent
cf6121e3da
commit
b9557064bf
|
@ -48,9 +48,10 @@ class ReadMarkerHandler(BaseHandler):
|
||||||
should_update = True
|
should_update = True
|
||||||
|
|
||||||
if existing_read_marker:
|
if existing_read_marker:
|
||||||
|
# Only update if the new marker is ahead in the stream
|
||||||
should_update = yield self.store.is_event_after(
|
should_update = yield self.store.is_event_after(
|
||||||
existing_read_marker['marker'],
|
event_id,
|
||||||
event_id
|
existing_read_marker['marker']
|
||||||
)
|
)
|
||||||
|
|
||||||
if should_update:
|
if should_update:
|
||||||
|
|
|
@ -2161,18 +2161,11 @@ class EventsStore(SQLBaseStore):
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def is_event_after(self, event_id1, event_id2):
|
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_1, so_1 = yield self._get_event_ordering(event_id1)
|
||||||
to_2, so_2 = yield self._get_event_ordering(event_id2)
|
to_2, so_2 = yield self._get_event_ordering(event_id2)
|
||||||
|
defer.returnValue(to_1 > to_2 and so_1 > so_2)
|
||||||
# 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.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def _get_event_ordering(self, event_id):
|
def _get_event_ordering(self, event_id):
|
||||||
|
|
Loading…
Reference in New Issue