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

Commit aa0a109

Browse files
committed
More comment clarification and fix argument typos
1 parent 225675b commit aa0a109

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

synapse/handlers/room_batch.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ async def persist_state_events_at_start(
174174
assert app_service_requester.app_service
175175

176176
state_event_ids_at_start = []
177+
state_event_ids = initial_state_event_ids.copy()
177178

178179
# Make the state events float off on their own by specifying no
179180
# prev_events for the first one in the chain so we don't have a bunch of
@@ -212,16 +213,26 @@ async def persist_state_events_at_start(
212213
room_id=room_id,
213214
action=membership,
214215
content=event_dict["content"],
216+
# Mark as an outlier to disconnect it from the normal DAG
217+
# and not show up between batches of history.
215218
outlier=True,
216219
historical=True,
217220
# Only the first event in the state chain should be floating.
218221
# The rest should hang off each other in a chain.
219222
allow_no_prev_events=index == 0,
220223
prev_event_ids=prev_event_ids_for_state_chain,
221-
# Since the first event in the state chain is floating with
222-
# no `prev_events`, it can't derive state from anywhere
223-
# automatically. So we need to set some state explicitly.
224-
state_event_ids=initial_state_event_ids if index == 0 else None,
224+
# Since each state event is marked as an outlier, the
225+
# `EventContext.for_outlier()` won't have any `state_ids`
226+
# set and therefore can't derive any state even though the
227+
# prev_events are set. Also since the first event in the
228+
# state chain is floating with no `prev_events`, it can't
229+
# derive state from anywhere automatically. So we need to
230+
# set some state explicitly.
231+
#
232+
# Make sure to use a copy of this list because we modify it
233+
# later in the loop here. Otherwise it will be the same
234+
# reference and also update in the event when we append later.
235+
state_event_ids=state_event_ids.copy(),
225236
)
226237
else:
227238
# TODO: Add some complement tests that adds state that is not member joins
@@ -235,20 +246,31 @@ async def persist_state_events_at_start(
235246
state_event["sender"], app_service_requester.app_service
236247
),
237248
event_dict,
249+
# Mark as an outlier to disconnect it from the normal DAG
250+
# and not show up between batches of history.
238251
outlier=True,
239252
historical=True,
240253
# Only the first event in the state chain should be floating.
241254
# The rest should hang off each other in a chain.
242255
allow_no_prev_events=index == 0,
243256
prev_event_ids=prev_event_ids_for_state_chain,
244-
# Since the first event in the state chain is floating with
245-
# no `prev_events`, it can't derive state from anywhere
246-
# automatically. So we need to set some state explicitly.
247-
state_event_ids=initial_state_event_ids if index == 0 else None,
257+
# Since each state event is marked as an outlier, the
258+
# `EventContext.for_outlier()` won't have any `state_ids`
259+
# set and therefore can't derive any state even though the
260+
# prev_events are set. Also since the first event in the
261+
# state chain is floating with no `prev_events`, it can't
262+
# derive state from anywhere automatically. So we need to
263+
# set some state explicitly.
264+
#
265+
# Make sure to use a copy of this list because we modify it
266+
# later in the loop here. Otherwise it will be the same
267+
# reference and also update in the event when we append later.
268+
state_event_ids=state_event_ids.copy(),
248269
)
249270
event_id = event.event_id
250271

251272
state_event_ids_at_start.append(event_id)
273+
state_event_ids.append(event_id)
252274
# Connect all the state in a floating chain
253275
prev_event_ids_for_state_chain = [event_id]
254276

synapse/rest/client/room_batch.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ async def on_POST(
196196
),
197197
base_insertion_event_dict,
198198
prev_event_ids=base_insertion_event_dict.get("prev_events"),
199+
# TODO: Is state_event_ids necessary here?
199200
state_event_ids=state_event_ids,
200201
historical=True,
201202
depth=inherited_depth,
@@ -212,7 +213,7 @@ async def on_POST(
212213
room_id=room_id,
213214
batch_id_to_connect_to=batch_id_to_connect_to,
214215
inherited_depth=inherited_depth,
215-
state_event_ids=state_event_ids,
216+
initial_state_event_ids=state_event_ids,
216217
app_service_requester=requester,
217218
)
218219

0 commit comments

Comments
 (0)