mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-02 13:16:01 -04:00
Refactor event ordering check to events store
This commit is contained in:
parent
131485ef66
commit
73880268ef
2 changed files with 32 additions and 28 deletions
|
@ -2159,6 +2159,34 @@ class EventsStore(SQLBaseStore):
|
|||
]
|
||||
)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def is_event_after(self, event_id1, event_id2):
|
||||
is_after = True
|
||||
|
||||
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.inlineCallbacks
|
||||
def _get_event_ordering(self, event_id):
|
||||
res = yield self._simple_select_one(
|
||||
table="events",
|
||||
retcols=["topological_ordering", "stream_ordering"],
|
||||
keyvalues={"event_id": event_id},
|
||||
allow_none=True
|
||||
)
|
||||
|
||||
if not res:
|
||||
raise SynapseError(404, "Could not find event %s" % (event_id,))
|
||||
|
||||
defer.returnValue((int(res["topological_ordering"]), int(res["stream_ordering"])))
|
||||
|
||||
AllNewEventsResult = namedtuple("AllNewEventsResult", [
|
||||
"new_forward_events", "new_backfill_events",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue