Skip to content

Commit e5b9ce1

Browse files
committed
ban_list: slow query fix
Enumerating via the user_permissions view is slow; change this to only return room-specific bans (which makes more sense anyway) and use the `user_permissions_overrides` table for a much faster query.
1 parent c47cfb7 commit e5b9ce1

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

sogs/model/room.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,14 +1211,20 @@ def unban_user(self, to_unban: User, *, mod: User):
12111211

12121212
def get_bans(self):
12131213
"""
1214-
Retrieves all the session IDs banned from this room. This does not check permissions: i.e.
1215-
it should only be accessed by moderators/admins.
1214+
Retrieves all the session IDs specifically banned from this room (not including global
1215+
bans). This does not check permissions: i.e. it should only be accessed by
1216+
moderators/admins.
12161217
"""
12171218

12181219
return sorted(
12191220
r[0]
12201221
for r in query(
1221-
"SELECT session_id FROM user_permissions WHERE room = :r AND banned", r=self.id
1222+
"""
1223+
SELECT session_id
1224+
FROM user_permission_overrides upo JOIN users ON upo."user" = users.id
1225+
WHERE room = :r AND upo.banned
1226+
""",
1227+
r=self.id,
12221228
)
12231229
)
12241230

0 commit comments

Comments
 (0)