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

Reduce the amount of state we pull out #15968

Merged
merged 2 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions changelog.d/15968.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Reduce the amount of state we pull out.
6 changes: 2 additions & 4 deletions synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1581,9 +1581,7 @@ async def add_display_name_to_third_party_invite(
event.content["third_party_invite"]["signed"]["token"],
)
original_invite = None
prev_state_ids = await context.get_prev_state_ids(
StateFilter.from_types([(EventTypes.ThirdPartyInvite, None)])
)
prev_state_ids = await context.get_prev_state_ids(StateFilter.from_types([key]))
original_invite_id = prev_state_ids.get(key)
if original_invite_id:
original_invite = await self.store.get_event(
Expand Down Expand Up @@ -1636,7 +1634,7 @@ async def _check_signature(self, event: EventBase, context: EventContext) -> Non
token = signed["token"]

prev_state_ids = await context.get_prev_state_ids(
StateFilter.from_types([(EventTypes.ThirdPartyInvite, None)])
StateFilter.from_types([(EventTypes.ThirdPartyInvite, token)])
)
invite_event_id = prev_state_ids.get((EventTypes.ThirdPartyInvite, token))

Expand Down
4 changes: 2 additions & 2 deletions synapse/handlers/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ async def create_event(
prev_event_id = state_map.get((EventTypes.Member, event.sender))
else:
prev_state_ids = await unpersisted_context.get_prev_state_ids(
StateFilter.from_types([(EventTypes.Member, None)])
StateFilter.from_types([(EventTypes.Member, event.sender)])
)
prev_event_id = prev_state_ids.get((EventTypes.Member, event.sender))
prev_event = (
Expand Down Expand Up @@ -860,7 +860,7 @@ async def deduplicate_state_event(
return None

prev_state_ids = await context.get_prev_state_ids(
StateFilter.from_types([(event.type, None)])
StateFilter.from_types([(event.type, event.state_key)])
)
prev_event_id = prev_state_ids.get((event.type, event.state_key))
if not prev_event_id:
Expand Down
15 changes: 9 additions & 6 deletions synapse/handlers/room_member.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ async def _local_membership_update(
)
context = await unpersisted_context.persist(event)
prev_state_ids = await context.get_prev_state_ids(
StateFilter.from_types([(EventTypes.Member, None)])
StateFilter.from_types([(EventTypes.Member, user_id)])
)

prev_member_event_id = prev_state_ids.get(
Expand Down Expand Up @@ -1340,7 +1340,7 @@ async def send_membership_event(
requester = types.create_requester(target_user)

prev_state_ids = await context.get_prev_state_ids(
StateFilter.from_types([(EventTypes.GuestAccess, None)])
StateFilter.from_types([(EventTypes.GuestAccess, "")])
)
if event.membership == Membership.JOIN:
if requester.is_guest:
Expand All @@ -1362,11 +1362,14 @@ async def send_membership_event(
ratelimit=ratelimit,
)

prev_member_event_id = prev_state_ids.get(
(EventTypes.Member, event.state_key), None
)

if event.membership == Membership.LEAVE:
prev_state_ids = await context.get_prev_state_ids(
StateFilter.from_types([(EventTypes.Member, event.state_key)])
)
prev_member_event_id = prev_state_ids.get(
(EventTypes.Member, event.state_key), None
)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a bug fix, but isn't as we never actually use this function (currently) to send leave events.

if prev_member_event_id:
prev_member_event = await self.store.get_event(prev_member_event_id)
if prev_member_event.membership == Membership.JOIN:
Expand Down