diff options
author | Eric Eastwood <erice@element.io> | 2022-09-30 01:47:06 -0500 |
---|---|---|
committer | Eric Eastwood <erice@element.io> | 2022-09-30 01:47:06 -0500 |
commit | 8e204d6836c4268b4a1c21e8a79153f207d912e6 (patch) | |
tree | ee4c4f4b2de2e66d2722c054a8f0f4d49294e9d0 | |
parent | Fix the bug accidentally nesting lists (diff) | |
download | synapse-madlittlemods/no-more-floating-msc2716-batches.tar.xz |
Connect historical state chain to event chain github/madlittlemods/no-more-floating-msc2716-batches madlittlemods/no-more-floating-msc2716-batches
-rw-r--r-- | synapse/handlers/room_batch.py | 34 | ||||
-rw-r--r-- | synapse/rest/client/room_batch.py | 22 |
2 files changed, 18 insertions, 38 deletions
diff --git a/synapse/handlers/room_batch.py b/synapse/handlers/room_batch.py index 1572ea8209..1b87f09903 100644 --- a/synapse/handlers/room_batch.py +++ b/synapse/handlers/room_batch.py @@ -239,7 +239,7 @@ class RoomBatchHandler: events_to_create: List[JsonDict], room_id: str, inherited_depth: int, - initial_state_event_ids: List[str], + state_chain_event_id_to_connect_to: str, app_service_requester: Requester, ) -> List[str]: """Create and persists all events provided sequentially. Handles the @@ -255,10 +255,7 @@ class RoomBatchHandler: room_id: Room where you want the events persisted in. inherited_depth: The depth to create the events at (you will probably by calling inherit_depth_from_prev_ids(...)). - initial_state_event_ids: - This is used to set explicit state for the insertion event at - the start of the historical batch since it's floating with no - prev_events to derive state from automatically. + state_chain_event_id_to_connect_to: TODO: HERE app_service_requester: The requester of an application service. Returns: @@ -271,10 +268,8 @@ class RoomBatchHandler: # We expect the last event in a historical batch to be an batch event assert events_to_create[-1]["type"] == EventTypes.MSC2716_BATCH - # Make the historical event chain float off on its own by specifying no - # prev_events for the first event in the chain which causes the HS to - # ask for the state at the start of the batch later. - prev_event_ids: List[str] = [] + # Connect the historical event chain to the state chain + prev_event_ids: List[str] = [state_chain_event_id_to_connect_to] event_ids = [] events_to_persist = [] @@ -302,16 +297,7 @@ class RoomBatchHandler: ev["sender"], app_service_requester.app_service ), event_dict, - # Only the first event (which is the insertion event) in the - # chain should be floating. The rest should hang off each other - # in a chain. - allow_no_prev_events=index == 0, prev_event_ids=event_dict.get("prev_events"), - # Since the first event (which is the insertion event) in the - # chain is floating with no `prev_events`, it can't derive state - # from anywhere automatically. So we need to set some state - # explicitly. - state_event_ids=initial_state_event_ids if index == 0 else None, historical=True, depth=inherited_depth, ) @@ -360,7 +346,7 @@ class RoomBatchHandler: room_id: str, batch_id_to_connect_to: str, inherited_depth: int, - initial_state_event_ids: List[str], + state_chain_event_id_to_connect_to: str, app_service_requester: Requester, ) -> Tuple[List[str], str]: """ @@ -375,13 +361,7 @@ class RoomBatchHandler: want this batch to connect to. inherited_depth: The depth to create the events at (you will probably by calling inherit_depth_from_prev_ids(...)). - initial_state_event_ids: - This is used to set explicit state for the insertion event at - the start of the historical batch since it's floating with no - prev_events to derive state from automatically. This should - probably be the state from the `prev_event` defined by - `/batch_send?prev_event_id=$abc` plus the outcome of - `persist_state_events_at_start` + state_chain_event_id_to_connect_to: TODO: HERE app_service_requester: The requester of an application service. Returns: @@ -427,7 +407,7 @@ class RoomBatchHandler: events_to_create=events_to_create, room_id=room_id, inherited_depth=inherited_depth, - initial_state_event_ids=initial_state_event_ids, + state_chain_event_id_to_connect_to=state_chain_event_id_to_connect_to, app_service_requester=app_service_requester, ) diff --git a/synapse/rest/client/room_batch.py b/synapse/rest/client/room_batch.py index 3c865431f1..496c8bc567 100644 --- a/synapse/rest/client/room_batch.py +++ b/synapse/rest/client/room_batch.py @@ -145,17 +145,16 @@ class RoomBatchSendEventRestServlet(RestServlet): ) state_event_ids_at_start = [] - # Create and persist all of the state events that float off on their own - # before the batch. These will most likely be all of the invite/member - # state events used to auth the upcoming historical messages. + # Create and persist all of the state events in a chain before the + # batch. These will most likely be all of the invite/member state events + # used to auth the upcoming historical messages. if body["state_events_at_start"]: - state_event_ids_at_start = ( - await self.room_batch_handler.persist_state_events_at_start( - state_events_at_start=body["state_events_at_start"], - room_id=room_id, - initial_prev_event_ids=prev_event_ids_from_query, - app_service_requester=requester, - ) + state_event_ids_at_start = await self.room_batch_handler.persist_state_events_at_start( + state_events_at_start=body["state_events_at_start"], + room_id=room_id, + # Connect the state chain to prev_event we're inserting next to + initial_prev_event_ids=prev_event_ids_from_query, + app_service_requester=requester, ) # Update our ongoing auth event ID list with all of the new state we # just created @@ -222,7 +221,8 @@ class RoomBatchSendEventRestServlet(RestServlet): room_id=room_id, batch_id_to_connect_to=batch_id_to_connect_to, inherited_depth=inherited_depth, - initial_state_event_ids=state_event_ids, + # Connect the historical batch to the state chain + state_chain_event_id_to_connect_to=state_event_ids_at_start[-1], app_service_requester=requester, ) |