diff options
author | Luke Barnard <lukeb@openmarket.com> | 2017-04-11 17:34:09 +0100 |
---|---|---|
committer | Luke Barnard <lukeb@openmarket.com> | 2017-04-11 17:34:09 +0100 |
commit | 73880268ef7184d17ec369074d1d0d72de56f33c (patch) | |
tree | cdf1359a4c07f848c1a6edef94e8399f9ef4610d /synapse/handlers/read_marker.py | |
parent | Copyright (diff) | |
download | synapse-73880268ef7184d17ec369074d1d0d72de56f33c.tar.xz |
Refactor event ordering check to events store
Diffstat (limited to 'synapse/handlers/read_marker.py')
-rw-r--r-- | synapse/handlers/read_marker.py | 32 |
1 files changed, 4 insertions, 28 deletions
diff --git a/synapse/handlers/read_marker.py b/synapse/handlers/read_marker.py index 19decc2c63..c3882313e6 100644 --- a/synapse/handlers/read_marker.py +++ b/synapse/handlers/read_marker.py @@ -42,41 +42,17 @@ class ReadMarkerHandler(BaseHandler): """ # Get ordering for existing read marker - with (yield self.read_marker_linearizer.queue(room_id + "_" + user_id)): + with (yield self.read_marker_linearizer.queue((room_id, user_id))): account_data = yield self.store.get_account_data_for_room(user_id, room_id) existing_read_marker = account_data["m.read_marker"] should_update = True - res = yield self.store._simple_select_one( - table="events", - retcols=["topological_ordering", "stream_ordering"], - keyvalues={"event_id": event_id}, - allow_none=True - ) - - if not res: - raise SynapseError(404, 'Event does not exist') - if existing_read_marker: - new_to = int(res["topological_ordering"]) - new_so = int(res["stream_ordering"]) - - # Get ordering for existing read marker - res = yield self.store._simple_select_one( - table="events", - retcols=["topological_ordering", "stream_ordering"], - keyvalues={"event_id": existing_read_marker['marker']}, - allow_none=True + should_update = yield self.store.is_event_after( + existing_read_marker['marker'], + event_id ) - existing_to = int(res["topological_ordering"]) if res else None - existing_so = int(res["stream_ordering"]) if res else None - - # Prevent updating if the existing marker is ahead in the stream - if existing_to > new_to: - should_update = False - elif existing_to == new_to and existing_so >= new_so: - should_update = False if should_update: content = { |