Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 703e3a9

Browse files
Allow /createRoom to be run on workers (#10564)
Fixes #7867
1 parent 84469bd commit 703e3a9

File tree

4 files changed

+37
-35
lines changed

4 files changed

+37
-35
lines changed

changelog.d/10564.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add support for routing `/createRoom` to workers.

docs/workers.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ expressions:
214214
^/_matrix/federation/v1/send/
215215

216216
# Client API requests
217+
^/_matrix/client/(api/v1|r0|unstable)/createRoom$
217218
^/_matrix/client/(api/v1|r0|unstable)/publicRooms$
218219
^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/joined_members$
219220
^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/context/.*$

synapse/rest/client/room.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1141,10 +1141,10 @@ def register_servlets(hs: "HomeServer", http_server, is_worker=False):
11411141
JoinedRoomsRestServlet(hs).register(http_server)
11421142
RoomAliasListServlet(hs).register(http_server)
11431143
SearchRestServlet(hs).register(http_server)
1144+
RoomCreateRestServlet(hs).register(http_server)
11441145

11451146
# Some servlets only get registered for the main process.
11461147
if not is_worker:
1147-
RoomCreateRestServlet(hs).register(http_server)
11481148
RoomForgetRestServlet(hs).register(http_server)
11491149

11501150

synapse/storage/databases/main/room.py

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,40 @@ def __init__(self, database: DatabasePool, db_conn, hs):
7373

7474
self.config = hs.config
7575

76+
async def store_room(
77+
self,
78+
room_id: str,
79+
room_creator_user_id: str,
80+
is_public: bool,
81+
room_version: RoomVersion,
82+
):
83+
"""Stores a room.
84+
85+
Args:
86+
room_id: The desired room ID, can be None.
87+
room_creator_user_id: The user ID of the room creator.
88+
is_public: True to indicate that this room should appear in
89+
public room lists.
90+
room_version: The version of the room
91+
Raises:
92+
StoreError if the room could not be stored.
93+
"""
94+
try:
95+
await self.db_pool.simple_insert(
96+
"rooms",
97+
{
98+
"room_id": room_id,
99+
"creator": room_creator_user_id,
100+
"is_public": is_public,
101+
"room_version": room_version.identifier,
102+
"has_auth_chain_index": True,
103+
},
104+
desc="store_room",
105+
)
106+
except Exception as e:
107+
logger.error("store_room with room_id=%s failed: %s", room_id, e)
108+
raise StoreError(500, "Problem creating room.")
109+
76110
async def get_room(self, room_id: str) -> dict:
77111
"""Retrieve a room.
78112
@@ -1342,40 +1376,6 @@ async def upsert_room_on_join(self, room_id: str, room_version: RoomVersion):
13421376
lock=False,
13431377
)
13441378

1345-
async def store_room(
1346-
self,
1347-
room_id: str,
1348-
room_creator_user_id: str,
1349-
is_public: bool,
1350-
room_version: RoomVersion,
1351-
):
1352-
"""Stores a room.
1353-
1354-
Args:
1355-
room_id: The desired room ID, can be None.
1356-
room_creator_user_id: The user ID of the room creator.
1357-
is_public: True to indicate that this room should appear in
1358-
public room lists.
1359-
room_version: The version of the room
1360-
Raises:
1361-
StoreError if the room could not be stored.
1362-
"""
1363-
try:
1364-
await self.db_pool.simple_insert(
1365-
"rooms",
1366-
{
1367-
"room_id": room_id,
1368-
"creator": room_creator_user_id,
1369-
"is_public": is_public,
1370-
"room_version": room_version.identifier,
1371-
"has_auth_chain_index": True,
1372-
},
1373-
desc="store_room",
1374-
)
1375-
except Exception as e:
1376-
logger.error("store_room with room_id=%s failed: %s", room_id, e)
1377-
raise StoreError(500, "Problem creating room.")
1378-
13791379
async def maybe_store_room_on_outlier_membership(
13801380
self, room_id: str, room_version: RoomVersion
13811381
):

0 commit comments

Comments
 (0)