Skip to content

Commit ac1bf68

Browse files
Allow (un)block_room storage functions to be called on workers (#18119)
This is so workers can call these functions. This was preventing the [Delete Room Admin API](https://element-hq.github.io/synapse/latest/admin_api/rooms.html#version-2-new-version) from succeeding when `block: true` was specified. This was because we had `run_background_tasks_on` configured to run on a separate worker. As workers weren't able to call the `block_room` storage function before this PR, the (delete room) task failed when taken off the queue by the worker.
1 parent a0b7047 commit ac1bf68

File tree

2 files changed

+45
-44
lines changed

2 files changed

+45
-44
lines changed

changelog.d/18119.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a bug where the [Delete Room Admin API](https://element-hq.github.io/synapse/latest/admin_api/rooms.html#version-2-new-version) would fail if the `block` parameter was set to `true` and a worker other than the main process was configured to handle background tasks.

synapse/storage/databases/main/room.py

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,50 @@ def _quarantine_media_txn(
11811181

11821182
return total_media_quarantined
11831183

1184+
async def block_room(self, room_id: str, user_id: str) -> None:
1185+
"""Marks the room as blocked.
1186+
1187+
Can be called multiple times (though we'll only track the last user to
1188+
block this room).
1189+
1190+
Can be called on a room unknown to this homeserver.
1191+
1192+
Args:
1193+
room_id: Room to block
1194+
user_id: Who blocked it
1195+
"""
1196+
await self.db_pool.simple_upsert(
1197+
table="blocked_rooms",
1198+
keyvalues={"room_id": room_id},
1199+
values={},
1200+
insertion_values={"user_id": user_id},
1201+
desc="block_room",
1202+
)
1203+
await self.db_pool.runInteraction(
1204+
"block_room_invalidation",
1205+
self._invalidate_cache_and_stream,
1206+
self.is_room_blocked,
1207+
(room_id,),
1208+
)
1209+
1210+
async def unblock_room(self, room_id: str) -> None:
1211+
"""Remove the room from blocking list.
1212+
1213+
Args:
1214+
room_id: Room to unblock
1215+
"""
1216+
await self.db_pool.simple_delete(
1217+
table="blocked_rooms",
1218+
keyvalues={"room_id": room_id},
1219+
desc="unblock_room",
1220+
)
1221+
await self.db_pool.runInteraction(
1222+
"block_room_invalidation",
1223+
self._invalidate_cache_and_stream,
1224+
self.is_room_blocked,
1225+
(room_id,),
1226+
)
1227+
11841228
async def get_rooms_for_retention_period_in_range(
11851229
self, min_ms: Optional[int], max_ms: Optional[int], include_null: bool = False
11861230
) -> Dict[str, RetentionPolicy]:
@@ -2500,50 +2544,6 @@ async def add_room_report(
25002544
)
25012545
return next_id
25022546

2503-
async def block_room(self, room_id: str, user_id: str) -> None:
2504-
"""Marks the room as blocked.
2505-
2506-
Can be called multiple times (though we'll only track the last user to
2507-
block this room).
2508-
2509-
Can be called on a room unknown to this homeserver.
2510-
2511-
Args:
2512-
room_id: Room to block
2513-
user_id: Who blocked it
2514-
"""
2515-
await self.db_pool.simple_upsert(
2516-
table="blocked_rooms",
2517-
keyvalues={"room_id": room_id},
2518-
values={},
2519-
insertion_values={"user_id": user_id},
2520-
desc="block_room",
2521-
)
2522-
await self.db_pool.runInteraction(
2523-
"block_room_invalidation",
2524-
self._invalidate_cache_and_stream,
2525-
self.is_room_blocked,
2526-
(room_id,),
2527-
)
2528-
2529-
async def unblock_room(self, room_id: str) -> None:
2530-
"""Remove the room from blocking list.
2531-
2532-
Args:
2533-
room_id: Room to unblock
2534-
"""
2535-
await self.db_pool.simple_delete(
2536-
table="blocked_rooms",
2537-
keyvalues={"room_id": room_id},
2538-
desc="unblock_room",
2539-
)
2540-
await self.db_pool.runInteraction(
2541-
"block_room_invalidation",
2542-
self._invalidate_cache_and_stream,
2543-
self.is_room_blocked,
2544-
(room_id,),
2545-
)
2546-
25472547
async def clear_partial_state_room(self, room_id: str) -> Optional[int]:
25482548
"""Clears the partial state flag for a room.
25492549

0 commit comments

Comments
 (0)