Skip to content

Commit a2e6f43

Browse files
authored
Fix bug with creating public rooms on workers (#17177)
If room publication is disabled then creating public rooms on workers would not work. Introduced in #16811.
1 parent 4cf4a82 commit a2e6f43

File tree

2 files changed

+52
-65
lines changed

2 files changed

+52
-65
lines changed

changelog.d/17177.bugfix

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix bug where disabling room publication prevented public rooms being created on workers.

synapse/storage/databases/main/room.py

+51-65
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@
2121
#
2222

2323
import logging
24-
from abc import abstractmethod
2524
from enum import Enum
2625
from typing import (
2726
TYPE_CHECKING,
2827
AbstractSet,
2928
Any,
30-
Awaitable,
3129
Collection,
3230
Dict,
3331
List,
@@ -1935,13 +1933,57 @@ def _get_rooms(txn: LoggingTransaction) -> List[str]:
19351933

19361934
return len(rooms)
19371935

1938-
@abstractmethod
1939-
def set_room_is_public(self, room_id: str, is_public: bool) -> Awaitable[None]:
1940-
# this will need to be implemented if a background update is performed with
1941-
# existing (tombstoned, public) rooms in the database.
1942-
#
1943-
# It's overridden by RoomStore for the synapse master.
1944-
raise NotImplementedError()
1936+
async def set_room_is_public(self, room_id: str, is_public: bool) -> None:
1937+
await self.db_pool.simple_update_one(
1938+
table="rooms",
1939+
keyvalues={"room_id": room_id},
1940+
updatevalues={"is_public": is_public},
1941+
desc="set_room_is_public",
1942+
)
1943+
1944+
async def set_room_is_public_appservice(
1945+
self, room_id: str, appservice_id: str, network_id: str, is_public: bool
1946+
) -> None:
1947+
"""Edit the appservice/network specific public room list.
1948+
1949+
Each appservice can have a number of published room lists associated
1950+
with them, keyed off of an appservice defined `network_id`, which
1951+
basically represents a single instance of a bridge to a third party
1952+
network.
1953+
1954+
Args:
1955+
room_id
1956+
appservice_id
1957+
network_id
1958+
is_public: Whether to publish or unpublish the room from the list.
1959+
"""
1960+
1961+
if is_public:
1962+
await self.db_pool.simple_upsert(
1963+
table="appservice_room_list",
1964+
keyvalues={
1965+
"appservice_id": appservice_id,
1966+
"network_id": network_id,
1967+
"room_id": room_id,
1968+
},
1969+
values={},
1970+
insertion_values={
1971+
"appservice_id": appservice_id,
1972+
"network_id": network_id,
1973+
"room_id": room_id,
1974+
},
1975+
desc="set_room_is_public_appservice_true",
1976+
)
1977+
else:
1978+
await self.db_pool.simple_delete(
1979+
table="appservice_room_list",
1980+
keyvalues={
1981+
"appservice_id": appservice_id,
1982+
"network_id": network_id,
1983+
"room_id": room_id,
1984+
},
1985+
desc="set_room_is_public_appservice_false",
1986+
)
19451987

19461988
async def has_auth_chain_index(self, room_id: str) -> bool:
19471989
"""Check if the room has (or can have) a chain cover index.
@@ -2349,62 +2391,6 @@ async def maybe_store_room_on_outlier_membership(
23492391
},
23502392
)
23512393

2352-
async def set_room_is_public(self, room_id: str, is_public: bool) -> None:
2353-
await self.db_pool.simple_update_one(
2354-
table="rooms",
2355-
keyvalues={"room_id": room_id},
2356-
updatevalues={"is_public": is_public},
2357-
desc="set_room_is_public",
2358-
)
2359-
2360-
self.hs.get_notifier().on_new_replication_data()
2361-
2362-
async def set_room_is_public_appservice(
2363-
self, room_id: str, appservice_id: str, network_id: str, is_public: bool
2364-
) -> None:
2365-
"""Edit the appservice/network specific public room list.
2366-
2367-
Each appservice can have a number of published room lists associated
2368-
with them, keyed off of an appservice defined `network_id`, which
2369-
basically represents a single instance of a bridge to a third party
2370-
network.
2371-
2372-
Args:
2373-
room_id
2374-
appservice_id
2375-
network_id
2376-
is_public: Whether to publish or unpublish the room from the list.
2377-
"""
2378-
2379-
if is_public:
2380-
await self.db_pool.simple_upsert(
2381-
table="appservice_room_list",
2382-
keyvalues={
2383-
"appservice_id": appservice_id,
2384-
"network_id": network_id,
2385-
"room_id": room_id,
2386-
},
2387-
values={},
2388-
insertion_values={
2389-
"appservice_id": appservice_id,
2390-
"network_id": network_id,
2391-
"room_id": room_id,
2392-
},
2393-
desc="set_room_is_public_appservice_true",
2394-
)
2395-
else:
2396-
await self.db_pool.simple_delete(
2397-
table="appservice_room_list",
2398-
keyvalues={
2399-
"appservice_id": appservice_id,
2400-
"network_id": network_id,
2401-
"room_id": room_id,
2402-
},
2403-
desc="set_room_is_public_appservice_false",
2404-
)
2405-
2406-
self.hs.get_notifier().on_new_replication_data()
2407-
24082394
async def add_event_report(
24092395
self,
24102396
room_id: str,

0 commit comments

Comments
 (0)