This commit is contained in:
Brendan Abolivier 2020-01-16 09:55:11 +00:00
parent 48e57a6452
commit e601f35d3b
No known key found for this signature in database
GPG Key ID: 1E015C145F1916CD

View File

@ -539,7 +539,9 @@ class StreamWorkerStore(EventsWorkerStore, SQLBaseStore):
return self.db.runInteraction( return self.db.runInteraction(
"get_room_event_after_stream_ordering", "get_room_event_after_stream_ordering",
self.get_room_event_around_stream_ordering_txn, self.get_room_event_around_stream_ordering_txn,
room_id, stream_ordering, "f", room_id,
stream_ordering,
"f",
) )
def get_room_event_before_stream_ordering(self, room_id, stream_ordering): def get_room_event_before_stream_ordering(self, room_id, stream_ordering):
@ -556,7 +558,9 @@ class StreamWorkerStore(EventsWorkerStore, SQLBaseStore):
return self.db.runInteraction( return self.db.runInteraction(
"get_room_event_before_stream_ordering", "get_room_event_before_stream_ordering",
self.get_room_event_around_stream_ordering_txn, self.get_room_event_around_stream_ordering_txn,
room_id, stream_ordering, "b", room_id,
stream_ordering,
"b",
) )
def get_room_event_around_stream_ordering_txn( def get_room_event_around_stream_ordering_txn(
@ -575,6 +579,11 @@ class StreamWorkerStore(EventsWorkerStore, SQLBaseStore):
Deferred[(int, int, str)]: Deferred[(int, int, str)]:
(stream ordering, topological ordering, event_id) (stream ordering, topological ordering, event_id)
""" """
# Figure out which comparison operation to perform and how to order the results,
# using the provided direction.
op = "<=" if dir == "b" else ">="
order = "DESC" if dir == "b" else "ASC"
sql = ( sql = (
"SELECT stream_ordering, topological_ordering, event_id" "SELECT stream_ordering, topological_ordering, event_id"
" FROM events" " FROM events"
@ -582,10 +591,7 @@ class StreamWorkerStore(EventsWorkerStore, SQLBaseStore):
" AND NOT outlier" " AND NOT outlier"
" ORDER BY stream_ordering %s" " ORDER BY stream_ordering %s"
" LIMIT 1" " LIMIT 1"
) % ( ) % (op, order)
"<=" if dir == "b" else ">=",
"DESC" if dir == "b" else "ASC",
)
txn.execute(sql, (room_id, stream_ordering)) txn.execute(sql, (room_id, stream_ordering))
return txn.fetchone() return txn.fetchone()