mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-13 06:52:17 -04:00
Make pagination of rooms in admin api stable (#11737)
Always add state.room_id after the configurable ORDER BY. Otherwise, for any sort, certain pages can contain results from other pages. (Especially when sorting by creator, since there may be many rooms by the same creator) * Document different order direction of numerical fields "joined_members", "joined_local_members", "version" and "state_events" are ordered in descending direction by default (dir=f). Added a note in tests to explain the differences in ordering. Signed-off-by: Daniël Sonck <daniel@sonck.nl>
This commit is contained in:
parent
e7da1ced24
commit
6b241f5286
3 changed files with 38 additions and 28 deletions
|
@ -551,24 +551,24 @@ class RoomWorkerStore(CacheInvalidationWorkerStore):
|
|||
FROM room_stats_state state
|
||||
INNER JOIN room_stats_current curr USING (room_id)
|
||||
INNER JOIN rooms USING (room_id)
|
||||
%s
|
||||
ORDER BY %s %s
|
||||
{where}
|
||||
ORDER BY {order_by} {direction}, state.room_id {direction}
|
||||
LIMIT ?
|
||||
OFFSET ?
|
||||
""" % (
|
||||
where_statement,
|
||||
order_by_column,
|
||||
"ASC" if order_by_asc else "DESC",
|
||||
""".format(
|
||||
where=where_statement,
|
||||
order_by=order_by_column,
|
||||
direction="ASC" if order_by_asc else "DESC",
|
||||
)
|
||||
|
||||
# Use a nested SELECT statement as SQL can't count(*) with an OFFSET
|
||||
count_sql = """
|
||||
SELECT count(*) FROM (
|
||||
SELECT room_id FROM room_stats_state state
|
||||
%s
|
||||
{where}
|
||||
) AS get_room_ids
|
||||
""" % (
|
||||
where_statement,
|
||||
""".format(
|
||||
where=where_statement,
|
||||
)
|
||||
|
||||
def _get_rooms_paginate_txn(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue