From 109d8b7aa95eee815556b394a53e18cec2dd5066 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 15 Jul 2022 10:18:08 +0100 Subject: [PATCH 1/2] Don't pull out full state when create an event --- synapse/events/builder.py | 8 +++++++- synapse/state/__init__.py | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/synapse/events/builder.py b/synapse/events/builder.py index 4caf6cbdee9d..17f624b68f58 100644 --- a/synapse/events/builder.py +++ b/synapse/events/builder.py @@ -24,9 +24,11 @@ RoomVersion, ) from synapse.crypto.event_signing import add_hashes_and_signatures +from synapse.event_auth import auth_types_for_event from synapse.events import EventBase, _EventInternalMetadata, make_event_from_dict from synapse.state import StateHandler from synapse.storage.databases.main import DataStore +from synapse.storage.state import StateFilter from synapse.types import EventID, JsonDict from synapse.util import Clock from synapse.util.stringutils import random_string @@ -121,7 +123,11 @@ async def build( """ if auth_event_ids is None: state_ids = await self._state.compute_state_after_events( - self.room_id, prev_event_ids + self.room_id, + prev_event_ids, + state_filter=StateFilter.from_types( + auth_types_for_event(self.room_version, self) + ), ) auth_event_ids = self._event_auth_handler.compute_auth_events( self, state_ids diff --git a/synapse/state/__init__.py b/synapse/state/__init__.py index 56606e9afbc6..384264ccae05 100644 --- a/synapse/state/__init__.py +++ b/synapse/state/__init__.py @@ -157,6 +157,7 @@ async def compute_state_after_events( self, room_id: str, event_ids: Collection[str], + state_filter: Optional[StateFilter] = None, ) -> StateMap[str]: """Fetch the state after each of the given event IDs. Resolve them and return. @@ -174,7 +175,7 @@ async def compute_state_after_events( """ logger.debug("calling resolve_state_groups from compute_state_after_events") ret = await self.resolve_state_groups_for_events(room_id, event_ids) - return await ret.get_state(self._state_storage_controller, StateFilter.all()) + return await ret.get_state(self._state_storage_controller, state_filter) async def get_current_users_in_room( self, room_id: str, latest_event_ids: List[str] From 11df05540c2ead735c450430ae758dc4bed2c833 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 15 Jul 2022 10:25:30 +0100 Subject: [PATCH 2/2] Newsfile --- changelog.d/13281.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/13281.misc diff --git a/changelog.d/13281.misc b/changelog.d/13281.misc new file mode 100644 index 000000000000..dea51d136279 --- /dev/null +++ b/changelog.d/13281.misc @@ -0,0 +1 @@ +Don't pull out the full state when creating an event.