Skip to content

Commit

Permalink
Fix popping room
Browse files Browse the repository at this point in the history
  • Loading branch information
MadLittleMods committed Sep 18, 2024
1 parent 8b989b3 commit 689905e
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions synapse/handlers/sliding_sync/room_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@
logger = logging.getLogger(__name__)


class Sentinel(enum.Enum):
# defining a sentinel in this way allows mypy to correctly handle the
# type of a dictionary lookup and subsequent type narrowing.
UNSET_SENTINEL = object()


# Helper definition for the types that we might return. We do this to avoid
# copying data between types (which can be expensive for many rooms).
RoomsForUserType = Union[RoomsForUserStateReset, RoomsForUser, RoomsForUserSlidingSync]
Expand Down Expand Up @@ -117,12 +123,6 @@ class SlidingSyncInterestedRooms:
dm_room_ids: AbstractSet[str]


class Sentinel(enum.Enum):
# defining a sentinel in this way allows mypy to correctly handle the
# type of a dictionary lookup and subsequent type narrowing.
UNSET_SENTINEL = object()


def filter_membership_for_sync(
*,
user_id: str,
Expand Down Expand Up @@ -234,7 +234,7 @@ async def _compute_interested_rooms_new_tables(
for room_id, change in changes.items():
if change is None:
# Remove rooms that the user joined after the `to_token`
room_membership_for_user_map.pop(room_id)
room_membership_for_user_map.pop(room_id, None)
continue

existing_room = room_membership_for_user_map.get(room_id)
Expand Down Expand Up @@ -272,6 +272,7 @@ async def _compute_interested_rooms_new_tables(
newly_left_room_map.keys() - room_membership_for_user_map.keys()
)
if missing_newly_left_rooms:
# TODO: It would be nice to avoid these copies
room_membership_for_user_map = dict(room_membership_for_user_map)
for room_id in missing_newly_left_rooms:
# The type here is `RoomsForUserStateReset` but that's just because
Expand Down Expand Up @@ -457,6 +458,9 @@ async def _compute_interested_rooms_new_tables(

if sync_config.room_subscriptions:
with start_active_span("assemble_room_subscriptions"):
# TODO: It would be nice to avoid these copies
room_membership_for_user_map = dict(room_membership_for_user_map)

# Find which rooms are partially stated and may need to be filtered out
# depending on the `required_state` requested (see below).
partial_state_rooms = await self.store.get_partial_rooms()
Expand Down

0 comments on commit 689905e

Please sign in to comment.