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

Make pagination of rooms in admin api stable #11737

Merged
merged 5 commits into from
Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/11737.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make the list rooms admin api sort stable. Contributed by Daniël Sonck.
2 changes: 1 addition & 1 deletion synapse/storage/databases/main/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ async def get_rooms_paginate(
INNER JOIN room_stats_current curr USING (room_id)
INNER JOIN rooms USING (room_id)
%s
ORDER BY %s %s
ORDER BY %s %s, state.room_id ASC
dsonck92 marked this conversation as resolved.
Show resolved Hide resolved
LIMIT ?
OFFSET ?
""" % (
Expand Down
36 changes: 21 additions & 15 deletions tests/rest/admin/test_room.py
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,8 @@ def test_list_rooms(self) -> None:
)
room_ids.append(room_id)

room_ids.sort()

# Request the list of rooms
url = "/_synapse/admin/v1/rooms"
channel = self.make_request(
Expand Down Expand Up @@ -1360,6 +1362,10 @@ def _order_test(
room_id_2 = self.helper.create_room_as(self.admin_user, tok=self.admin_user_tok)
room_id_3 = self.helper.create_room_as(self.admin_user, tok=self.admin_user_tok)

# Also create a list sorted by IDs for properties that are equal (and thus sorted by room_id)
all_ids = [room_id_1, room_id_2, room_id_3]
dsonck92 marked this conversation as resolved.
Show resolved Hide resolved
all_ids.sort()

# Set room names in alphabetical order. room 1 -> A, 2 -> B, 3 -> C
self.helper.send_state(
room_id_1,
Expand Down Expand Up @@ -1413,31 +1419,31 @@ def _order_test(
"joined_local_members", [room_id_1, room_id_2, room_id_3], reverse=True
)

_order_test("version", [room_id_1, room_id_2, room_id_3])
_order_test("version", [room_id_1, room_id_2, room_id_3], reverse=True)
_order_test("version", all_ids)
_order_test("version", all_ids, reverse=True)

_order_test("creator", [room_id_1, room_id_2, room_id_3])
_order_test("creator", [room_id_1, room_id_2, room_id_3], reverse=True)
_order_test("creator", all_ids)
_order_test("creator", all_ids, reverse=True)

_order_test("encryption", [room_id_1, room_id_2, room_id_3])
_order_test("encryption", [room_id_1, room_id_2, room_id_3], reverse=True)
_order_test("encryption", all_ids)
_order_test("encryption", all_ids, reverse=True)

_order_test("federatable", [room_id_1, room_id_2, room_id_3])
_order_test("federatable", [room_id_1, room_id_2, room_id_3], reverse=True)
_order_test("federatable", all_ids)
_order_test("federatable", all_ids, reverse=True)

_order_test("public", [room_id_1, room_id_2, room_id_3])
_order_test("public", all_ids)
# Different sort order of SQlite and PostreSQL
# _order_test("public", [room_id_3, room_id_2, room_id_1], reverse=True)

dsonck92 marked this conversation as resolved.
Show resolved Hide resolved
_order_test("join_rules", [room_id_1, room_id_2, room_id_3])
_order_test("join_rules", [room_id_1, room_id_2, room_id_3], reverse=True)
_order_test("join_rules", all_ids)
_order_test("join_rules", all_ids, reverse=True)

_order_test("guest_access", [room_id_1, room_id_2, room_id_3])
_order_test("guest_access", [room_id_1, room_id_2, room_id_3], reverse=True)
_order_test("guest_access", all_ids)
_order_test("guest_access", all_ids, reverse=True)
dsonck92 marked this conversation as resolved.
Show resolved Hide resolved

_order_test("history_visibility", [room_id_1, room_id_2, room_id_3])
_order_test("history_visibility", all_ids)
_order_test(
"history_visibility", [room_id_1, room_id_2, room_id_3], reverse=True
"history_visibility", all_ids, reverse=True
)

_order_test("state_events", [room_id_3, room_id_2, room_id_1])
Expand Down