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

Convert all namedtuples to attrs. #11665

Merged
merged 17 commits into from
Dec 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions synapse/handlers/appservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,9 @@ async def query_room_alias_exists(

Args:
room_alias: The room alias to query.

Returns:
namedtuple: with keys "room_id" and "servers" or None if no
association can be found.
RoomAliasMapping or None if no association can be found.
"""
room_alias_str = room_alias.to_string()
services = self.store.get_app_services()
Expand Down
8 changes: 5 additions & 3 deletions synapse/handlers/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,13 @@ async def get_association(self, room_alias: RoomAlias) -> JsonDict:

users = await self.store.get_users_in_room(room_id)
extra_servers = {get_domain_from_id(u) for u in users}
servers = set(extra_servers) | set(servers)
unique_servers = set(extra_servers) | set(servers)
clokep marked this conversation as resolved.
Show resolved Hide resolved

# If this server is in the list of servers, return it first.
if self.server_name in servers:
servers = [self.server_name] + [s for s in servers if s != self.server_name]
if self.server_name in unique_servers:
servers = [self.server_name] + [
s for s in unique_servers if s != self.server_name
]
else:
servers = list(servers)

Expand Down
10 changes: 8 additions & 2 deletions synapse/storage/databases/main/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,22 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from collections import namedtuple
from typing import Iterable, List, Optional, Tuple

import attr

from synapse.api.errors import SynapseError
from synapse.storage.database import LoggingTransaction
from synapse.storage.databases.main import CacheInvalidationWorkerStore
from synapse.types import RoomAlias
from synapse.util.caches.descriptors import cached

RoomAliasMapping = namedtuple("RoomAliasMapping", ("room_id", "room_alias", "servers"))

@attr.s(slots=True, frozen=True, auto_attribs=True)
class RoomAliasMapping:
room_id: str
room_alias: str
servers: List[str]


class DirectoryWorkerStore(CacheInvalidationWorkerStore):
Expand Down