@@ -233,24 +233,23 @@ def _count_public_rooms_txn(txn: LoggingTransaction) -> int:
233
233
UNION SELECT room_id from appservice_room_list
234
234
"""
235
235
236
- sql = """
236
+ sql = f """
237
237
SELECT
238
238
COUNT(*)
239
239
FROM (
240
- %( published_sql)s
240
+ { published_sql }
241
241
) published
242
242
INNER JOIN room_stats_state USING (room_id)
243
243
INNER JOIN room_stats_current USING (room_id)
244
244
WHERE
245
245
(
246
- join_rules = 'public' OR join_rules = '%(knock_join_rule)s'
246
+ join_rules = '{ JoinRules .PUBLIC } '
247
+ OR join_rules = '{ JoinRules .KNOCK } '
248
+ OR join_rules = '{ JoinRules .KNOCK_RESTRICTED } '
247
249
OR history_visibility = 'world_readable'
248
250
)
249
251
AND joined_members > 0
250
- """ % {
251
- "published_sql" : published_sql ,
252
- "knock_join_rule" : JoinRules .KNOCK ,
253
- }
252
+ """
254
253
255
254
txn .execute (sql , query_args )
256
255
return cast (Tuple [int ], txn .fetchone ())[0 ]
@@ -369,29 +368,29 @@ async def get_largest_public_rooms(
369
368
if where_clauses :
370
369
where_clause = " AND " + " AND " .join (where_clauses )
371
370
372
- sql = """
371
+ dir = "DESC" if forwards else "ASC"
372
+ sql = f"""
373
373
SELECT
374
374
room_id, name, topic, canonical_alias, joined_members,
375
375
avatar, history_visibility, guest_access, join_rules
376
376
FROM (
377
- %( published_sql)s
377
+ { published_sql }
378
378
) published
379
379
INNER JOIN room_stats_state USING (room_id)
380
380
INNER JOIN room_stats_current USING (room_id)
381
381
WHERE
382
382
(
383
- join_rules = 'public' OR join_rules = '%(knock_join_rule)s'
383
+ join_rules = '{ JoinRules .PUBLIC } '
384
+ OR join_rules = '{ JoinRules .KNOCK } '
385
+ OR join_rules = '{ JoinRules .KNOCK_RESTRICTED } '
384
386
OR history_visibility = 'world_readable'
385
387
)
386
388
AND joined_members > 0
387
- %(where_clause)s
388
- ORDER BY joined_members %(dir)s, room_id %(dir)s
389
- """ % {
390
- "published_sql" : published_sql ,
391
- "where_clause" : where_clause ,
392
- "dir" : "DESC" if forwards else "ASC" ,
393
- "knock_join_rule" : JoinRules .KNOCK ,
394
- }
389
+ { where_clause }
390
+ ORDER BY
391
+ joined_members { dir } ,
392
+ room_id { dir }
393
+ """
395
394
396
395
if limit is not None :
397
396
query_args .append (limit )
0 commit comments