-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Make pagination of rooms in admin api stable #11737
Changes from all commits
942a055
2fdeced
d2e595f
93a1ecf
4d15a5d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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. |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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( | ||||||||||||||
|
|
@@ -1360,6 +1362,12 @@ 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) | ||||||||||||||
| sorted_by_room_id_asc = [room_id_1, room_id_2, room_id_3] | ||||||||||||||
| sorted_by_room_id_asc.sort() | ||||||||||||||
| sorted_by_room_id_desc = sorted_by_room_id_asc.copy() | ||||||||||||||
| sorted_by_room_id_desc.reverse() | ||||||||||||||
|
|
||||||||||||||
| # Set room names in alphabetical order. room 1 -> A, 2 -> B, 3 -> C | ||||||||||||||
| self.helper.send_state( | ||||||||||||||
| room_id_1, | ||||||||||||||
|
|
@@ -1405,41 +1413,42 @@ def _order_test( | |||||||||||||
| _order_test("canonical_alias", [room_id_1, room_id_2, room_id_3]) | ||||||||||||||
| _order_test("canonical_alias", [room_id_3, room_id_2, room_id_1], reverse=True) | ||||||||||||||
|
|
||||||||||||||
| # Note: joined_member counts are sorted in descending order when dir=f | ||||||||||||||
| _order_test("joined_members", [room_id_3, room_id_2, room_id_1]) | ||||||||||||||
| _order_test("joined_members", [room_id_1, room_id_2, room_id_3], reverse=True) | ||||||||||||||
|
|
||||||||||||||
| # Note: joined_local_member counts are sorted in descending order when dir=f | ||||||||||||||
| _order_test("joined_local_members", [room_id_3, room_id_2, room_id_1]) | ||||||||||||||
| _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) | ||||||||||||||
| # Note: versions are sorted in descending order when dir=f | ||||||||||||||
| _order_test("version", sorted_by_room_id_asc, reverse=True) | ||||||||||||||
| _order_test("version", sorted_by_room_id_desc) | ||||||||||||||
|
Comment on lines
+1427
to
+1428
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have no idea why this requires the reverse to be swapped. It was required locally, maybe CI tests differently, but I cannot explain it since all rooms should be the same version, and reversing works the same (and correctly) for the rest of the test cases
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's odd. Thanks for flagging it up; let's see what CI says and maybe we can investigate in more detail later.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh, I think I see it now. The initial sort order is controlled by synapse/synapse/storage/databases/main/room.py Lines 506 to 511 in d2e595f
I guess the idea is to use the "natural" sort direction by default while still allowing the user to reverse it. Not sure if I agree with that choice, but it looks like the behaviour will be consistent.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (This goes back to #6720)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That indeed was the intention, and back then there were only two sort orders - size of joined members and alphabetical room names. It seemed sensible for users to want to view rooms sorted by size of joined members descending, whereas users would want to see room names sorted from a->z. Of course, client software could just set the I'm just coming into this conversation without much context... but I fail to see why setting the direction order based on ordering type is confusing.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In a nutshell, we have different interpretations of what
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aah I see, yes, in my case this will end up confusing: Because the arrow directly translates to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personally, I feel like the initial sort direction is the choice of the client, and the backend just returns exactly what you ask it. That way, the client can be written knowing exactly what it will return without looking at the docs/source code and without having some lookup table to correctly swap arrows based on field. Because if it does need a translation table, at that stage, you're essentially doing double work: backend is opinionated about sorting direction, so will pick a (well defined, but seemingly arbitrary) direction that can be flipped, and client compensates for this opinion by swapping the arrow to match the direction. If it's not doing the opinionated default direction, then there's a lot less lines necessary in the backend (since it's always asc or desc, unless flipped), and no logic in the client necessary to compensate for it. But! That's my opinion. I have to check with the existing synapse-admin to see if it actually takes this into account. Edit: No, it simply forwards as well. I would say, I can finish this PR based on current behavior and add the comments. Later it can be decided whether it's important.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the discussion both - I've ended up coming to the same conclusion. It is unnecessary to maintain this "lookup table" on both ends. I've created a separate issue to track this at #11759. |
||||||||||||||
|
|
||||||||||||||
| _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", sorted_by_room_id_asc) | ||||||||||||||
| _order_test("creator", sorted_by_room_id_desc, 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", sorted_by_room_id_asc) | ||||||||||||||
| _order_test("encryption", sorted_by_room_id_desc, 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", sorted_by_room_id_asc) | ||||||||||||||
| _order_test("federatable", sorted_by_room_id_desc, reverse=True) | ||||||||||||||
|
|
||||||||||||||
| _order_test("public", [room_id_1, room_id_2, room_id_3]) | ||||||||||||||
| # Different sort order of SQlite and PostreSQL | ||||||||||||||
| # _order_test("public", [room_id_3, room_id_2, room_id_1], reverse=True) | ||||||||||||||
| _order_test("public", sorted_by_room_id_asc) | ||||||||||||||
| _order_test("public", sorted_by_room_id_desc, 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", sorted_by_room_id_asc) | ||||||||||||||
| _order_test("join_rules", sorted_by_room_id_desc, 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", sorted_by_room_id_asc) | ||||||||||||||
| _order_test("guest_access", sorted_by_room_id_desc, reverse=True) | ||||||||||||||
|
|
||||||||||||||
| _order_test("history_visibility", [room_id_1, room_id_2, room_id_3]) | ||||||||||||||
| _order_test( | ||||||||||||||
| "history_visibility", [room_id_1, room_id_2, room_id_3], reverse=True | ||||||||||||||
| ) | ||||||||||||||
| _order_test("history_visibility", sorted_by_room_id_asc) | ||||||||||||||
| _order_test("history_visibility", sorted_by_room_id_desc, reverse=True) | ||||||||||||||
|
|
||||||||||||||
| # Note: state_event counts are sorted in descending order when dir=f | ||||||||||||||
| _order_test("state_events", [room_id_3, room_id_2, room_id_1]) | ||||||||||||||
| _order_test("state_events", [room_id_1, room_id_2, room_id_3], reverse=True) | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||

Uh oh!
There was an error while loading. Please reload this page.