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

Commit

Permalink
Change to FrozenSet
Browse files Browse the repository at this point in the history
  • Loading branch information
dklimpel committed May 14, 2022
1 parent 8b49b0f commit 18e0f49
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
24 changes: 17 additions & 7 deletions synapse/federation/sender/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@
import abc
import logging
from collections import OrderedDict
from typing import TYPE_CHECKING, Dict, Hashable, Iterable, List, Optional, Set, Tuple
from typing import (
TYPE_CHECKING,
Collection,
Dict,
Hashable,
Iterable,
List,
Optional,
Set,
Tuple,
)

import attr
from prometheus_client import Counter
Expand Down Expand Up @@ -409,7 +419,7 @@ async def handle_event(event: EventBase) -> None:
)
return

destinations: Optional[Set[str]] = None
destinations: Optional[Collection[str]] = None
if not event.prev_event_ids():
# If there are no prev event IDs then the state is empty
# and so no remote servers in the room
Expand Down Expand Up @@ -444,7 +454,7 @@ async def handle_event(event: EventBase) -> None:
)
return

destinations = {
sharded_destinations = {
d
for d in destinations
if self._federation_shard_config.should_handle(
Expand All @@ -456,12 +466,12 @@ async def handle_event(event: EventBase) -> None:
# If we are sending the event on behalf of another server
# then it already has the event and there is no reason to
# send the event to it.
destinations.discard(send_on_behalf_of)
sharded_destinations.discard(send_on_behalf_of)

logger.debug("Sending %s to %r", event, destinations)
logger.debug("Sending %s to %r", event, sharded_destinations)

if destinations:
await self._send_pdu(event, destinations)
if sharded_destinations:
await self._send_pdu(event, sharded_destinations)

now = self.clock.time_msec()
ts = await self.store.get_received_ts(event.event_id)
Expand Down
6 changes: 3 additions & 3 deletions synapse/handlers/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,9 @@ async def current_sync_for_user(

async def push_rules_for_user(self, user: UserID) -> Dict[str, Dict[str, list]]:
user_id = user.to_string()
rules = await self.store.get_push_rules_for_user(user_id)
result = format_push_rules_for_user(user, rules)
return result
rules_raw = await self.store.get_push_rules_for_user(user_id)
rules = format_push_rules_for_user(user, rules_raw )
return rules

async def ephemeral_by_room(
self,
Expand Down
4 changes: 2 additions & 2 deletions synapse/state/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,13 @@ async def get_current_users_in_room(
entry = await self.resolve_state_groups_for_events(room_id, latest_event_ids)
return await self.store.get_joined_users_from_state(room_id, entry)

async def get_current_hosts_in_room(self, room_id: str) -> Set[str]:
async def get_current_hosts_in_room(self, room_id: str) -> FrozenSet[str]:
event_ids = await self.store.get_latest_event_ids_in_room(room_id)
return await self.get_hosts_in_room_at_events(room_id, event_ids)

async def get_hosts_in_room_at_events(
self, room_id: str, event_ids: Collection[str]
) -> Set[str]:
) -> FrozenSet[str]:
"""Get the hosts that were in a room at the given event ids
Args:
Expand Down

0 comments on commit 18e0f49

Please sign in to comment.