Skip to content
This repository was archived by the owner on Mar 26, 2024. It is now read-only.

Commit b692ccf

Browse files
committed
Revert "Add order_by argument for paginating room events"
This reverts commit 31bac75.
1 parent 41e1b19 commit b692ccf

File tree

1 file changed

+6
-36
lines changed

1 file changed

+6
-36
lines changed

synapse/storage/databases/main/stream.py

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -672,31 +672,22 @@ def f(txn: LoggingTransaction) -> List[_EventDictReturn]:
672672
return ret
673673

674674
async def get_recent_events_for_room(
675-
self,
676-
room_id: str,
677-
limit: int,
678-
end_token: RoomStreamToken,
679-
order_by: str = "topological",
675+
self, room_id: str, limit: int, end_token: RoomStreamToken
680676
) -> Tuple[List[EventBase], RoomStreamToken]:
681677
"""Get the most recent events in the room in topological ordering.
682678
683679
Args:
684680
room_id
685681
limit
686682
end_token: The stream token representing now.
687-
order_by: Either 'topological' or 'stream' to indicate the order in
688-
which results should be returned.
689683
690684
Returns:
691685
A list of events and a token pointing to the start of the returned
692686
events. The events returned are in ascending topological order.
693687
"""
694688

695689
rows, token = await self.get_recent_event_ids_for_room(
696-
room_id,
697-
limit,
698-
end_token,
699-
order_by,
690+
room_id, limit, end_token
700691
)
701692

702693
events = await self.get_events_as_list(
@@ -708,20 +699,14 @@ async def get_recent_events_for_room(
708699
return events, token
709700

710701
async def get_recent_event_ids_for_room(
711-
self,
712-
room_id: str,
713-
limit: int,
714-
end_token: RoomStreamToken,
715-
order_by: str = "topological",
702+
self, room_id: str, limit: int, end_token: RoomStreamToken
716703
) -> Tuple[List[_EventDictReturn], RoomStreamToken]:
717704
"""Get the most recent events in the room in topological ordering.
718705
719706
Args:
720707
room_id
721708
limit
722709
end_token: The stream token representing now.
723-
order_by: Either 'topological' or 'stream' to indicate the order in
724-
which results should be returned.
725710
726711
Returns:
727712
A list of _EventDictReturn and a token pointing to the start of the
@@ -736,7 +721,6 @@ async def get_recent_event_ids_for_room(
736721
self._paginate_room_events_txn,
737722
room_id,
738723
from_token=end_token,
739-
order_by=order_by,
740724
limit=limit,
741725
)
742726

@@ -1164,7 +1148,6 @@ def _paginate_room_events_txn(
11641148
from_token: RoomStreamToken,
11651149
to_token: Optional[RoomStreamToken] = None,
11661150
direction: str = "b",
1167-
order_by: str = "topological",
11681151
limit: int = -1,
11691152
event_filter: Optional[Filter] = None,
11701153
) -> Tuple[List[_EventDictReturn], RoomStreamToken]:
@@ -1177,8 +1160,6 @@ def _paginate_room_events_txn(
11771160
to_token: A token which if given limits the results to only those before
11781161
direction: Either 'b' or 'f' to indicate whether we are paginating
11791162
forwards or backwards from `from_key`.
1180-
order_by: Either 'topological' or 'stream' to indicate the order in
1181-
which results should be returned.
11821163
limit: The maximum number of events to return.
11831164
event_filter: If provided filters the events to
11841165
those that match the filter.
@@ -1191,7 +1172,6 @@ def _paginate_room_events_txn(
11911172
"""
11921173

11931174
assert int(limit) >= 0
1194-
assert order_by in ("topological", "stream")
11951175

11961176
# Tokens really represent positions between elements, but we use
11971177
# the convention of pointing to the event before the gap. Hence
@@ -1202,12 +1182,6 @@ def _paginate_room_events_txn(
12021182
else:
12031183
order = "ASC"
12041184

1205-
order_clause = """ORDER BY event.topological_ordering %(order)s, event.stream_ordering %(order)s"""
1206-
if order_by == "stream":
1207-
order_clause = """ORDER BY event.stream_ordering %(order)s, event.topological_ordering %(order)s"""
1208-
1209-
order_clause = order_clause % {"order": order}
1210-
12111185
# The bounds for the stream tokens are complicated by the fact
12121186
# that we need to handle the instance_map part of the tokens. We do this
12131187
# by fetching all events between the min stream token and the maximum
@@ -1303,13 +1277,13 @@ def _paginate_room_events_txn(
13031277
FROM events AS event
13041278
%(join_clause)s
13051279
WHERE event.outlier = ? AND event.room_id = ? AND %(bounds)s
1306-
%(order_clause)s
1307-
LIMIT ?
1280+
ORDER BY event.topological_ordering %(order)s,
1281+
event.stream_ordering %(order)s LIMIT ?
13081282
""" % {
13091283
"select_keywords": select_keywords,
13101284
"join_clause": join_clause,
13111285
"bounds": bounds,
1312-
"order_clause": order_clause,
1286+
"order": order,
13131287
}
13141288

13151289
txn.execute(sql, args)
@@ -1350,7 +1324,6 @@ async def paginate_room_events(
13501324
from_key: RoomStreamToken,
13511325
to_key: Optional[RoomStreamToken] = None,
13521326
direction: str = "b",
1353-
order_by: str = "topological",
13541327
limit: int = -1,
13551328
event_filter: Optional[Filter] = None,
13561329
) -> Tuple[List[EventBase], RoomStreamToken]:
@@ -1362,8 +1335,6 @@ async def paginate_room_events(
13621335
to_key: A token which if given limits the results to only those before
13631336
direction: Either 'b' or 'f' to indicate whether we are paginating
13641337
forwards or backwards from `from_key`.
1365-
order_by: Either 'topological' or 'stream' to indicate the order in
1366-
which results should be returned.
13671338
limit: The maximum number of events to return.
13681339
event_filter: If provided filters the events to those that match the filter.
13691340
@@ -1381,7 +1352,6 @@ async def paginate_room_events(
13811352
from_key,
13821353
to_key,
13831354
direction,
1384-
order_by,
13851355
limit,
13861356
event_filter,
13871357
)

0 commit comments

Comments
 (0)