mirror of
https://github.com/element-hq/synapse
synced 2024-09-28 16:32:40 +00:00
Connect historical state chain to event chain
This commit is contained in:
parent
1268b7989c
commit
8e204d6836
2 changed files with 18 additions and 38 deletions
|
@ -239,7 +239,7 @@ class RoomBatchHandler:
|
||||||
events_to_create: List[JsonDict],
|
events_to_create: List[JsonDict],
|
||||||
room_id: str,
|
room_id: str,
|
||||||
inherited_depth: int,
|
inherited_depth: int,
|
||||||
initial_state_event_ids: List[str],
|
state_chain_event_id_to_connect_to: str,
|
||||||
app_service_requester: Requester,
|
app_service_requester: Requester,
|
||||||
) -> List[str]:
|
) -> List[str]:
|
||||||
"""Create and persists all events provided sequentially. Handles the
|
"""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.
|
room_id: Room where you want the events persisted in.
|
||||||
inherited_depth: The depth to create the events at (you will
|
inherited_depth: The depth to create the events at (you will
|
||||||
probably by calling inherit_depth_from_prev_ids(...)).
|
probably by calling inherit_depth_from_prev_ids(...)).
|
||||||
initial_state_event_ids:
|
state_chain_event_id_to_connect_to: TODO: HERE
|
||||||
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.
|
|
||||||
app_service_requester: The requester of an application service.
|
app_service_requester: The requester of an application service.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
@ -271,10 +268,8 @@ class RoomBatchHandler:
|
||||||
# We expect the last event in a historical batch to be an batch event
|
# We expect the last event in a historical batch to be an batch event
|
||||||
assert events_to_create[-1]["type"] == EventTypes.MSC2716_BATCH
|
assert events_to_create[-1]["type"] == EventTypes.MSC2716_BATCH
|
||||||
|
|
||||||
# Make the historical event chain float off on its own by specifying no
|
# Connect the historical event chain to the state chain
|
||||||
# prev_events for the first event in the chain which causes the HS to
|
prev_event_ids: List[str] = [state_chain_event_id_to_connect_to]
|
||||||
# ask for the state at the start of the batch later.
|
|
||||||
prev_event_ids: List[str] = []
|
|
||||||
|
|
||||||
event_ids = []
|
event_ids = []
|
||||||
events_to_persist = []
|
events_to_persist = []
|
||||||
|
@ -302,16 +297,7 @@ class RoomBatchHandler:
|
||||||
ev["sender"], app_service_requester.app_service
|
ev["sender"], app_service_requester.app_service
|
||||||
),
|
),
|
||||||
event_dict,
|
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"),
|
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,
|
historical=True,
|
||||||
depth=inherited_depth,
|
depth=inherited_depth,
|
||||||
)
|
)
|
||||||
|
@ -360,7 +346,7 @@ class RoomBatchHandler:
|
||||||
room_id: str,
|
room_id: str,
|
||||||
batch_id_to_connect_to: str,
|
batch_id_to_connect_to: str,
|
||||||
inherited_depth: int,
|
inherited_depth: int,
|
||||||
initial_state_event_ids: List[str],
|
state_chain_event_id_to_connect_to: str,
|
||||||
app_service_requester: Requester,
|
app_service_requester: Requester,
|
||||||
) -> Tuple[List[str], str]:
|
) -> Tuple[List[str], str]:
|
||||||
"""
|
"""
|
||||||
|
@ -375,13 +361,7 @@ class RoomBatchHandler:
|
||||||
want this batch to connect to.
|
want this batch to connect to.
|
||||||
inherited_depth: The depth to create the events at (you will
|
inherited_depth: The depth to create the events at (you will
|
||||||
probably by calling inherit_depth_from_prev_ids(...)).
|
probably by calling inherit_depth_from_prev_ids(...)).
|
||||||
initial_state_event_ids:
|
state_chain_event_id_to_connect_to: TODO: HERE
|
||||||
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`
|
|
||||||
app_service_requester: The requester of an application service.
|
app_service_requester: The requester of an application service.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
@ -427,7 +407,7 @@ class RoomBatchHandler:
|
||||||
events_to_create=events_to_create,
|
events_to_create=events_to_create,
|
||||||
room_id=room_id,
|
room_id=room_id,
|
||||||
inherited_depth=inherited_depth,
|
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,
|
app_service_requester=app_service_requester,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -145,17 +145,16 @@ class RoomBatchSendEventRestServlet(RestServlet):
|
||||||
)
|
)
|
||||||
|
|
||||||
state_event_ids_at_start = []
|
state_event_ids_at_start = []
|
||||||
# Create and persist all of the state events that float off on their own
|
# Create and persist all of the state events in a chain before the
|
||||||
# before the batch. These will most likely be all of the invite/member
|
# batch. These will most likely be all of the invite/member state events
|
||||||
# state events used to auth the upcoming historical messages.
|
# used to auth the upcoming historical messages.
|
||||||
if body["state_events_at_start"]:
|
if body["state_events_at_start"]:
|
||||||
state_event_ids_at_start = (
|
state_event_ids_at_start = await self.room_batch_handler.persist_state_events_at_start(
|
||||||
await self.room_batch_handler.persist_state_events_at_start(
|
state_events_at_start=body["state_events_at_start"],
|
||||||
state_events_at_start=body["state_events_at_start"],
|
room_id=room_id,
|
||||||
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,
|
initial_prev_event_ids=prev_event_ids_from_query,
|
||||||
app_service_requester=requester,
|
app_service_requester=requester,
|
||||||
)
|
|
||||||
)
|
)
|
||||||
# Update our ongoing auth event ID list with all of the new state we
|
# Update our ongoing auth event ID list with all of the new state we
|
||||||
# just created
|
# just created
|
||||||
|
@ -222,7 +221,8 @@ class RoomBatchSendEventRestServlet(RestServlet):
|
||||||
room_id=room_id,
|
room_id=room_id,
|
||||||
batch_id_to_connect_to=batch_id_to_connect_to,
|
batch_id_to_connect_to=batch_id_to_connect_to,
|
||||||
inherited_depth=inherited_depth,
|
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,
|
app_service_requester=requester,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue