mirror of
https://github.com/element-hq/synapse
synced 2024-08-20 15:30:21 +00:00
Decide which kind of prev_events we care about
This commit is contained in:
parent
620fa57ed8
commit
d711196db8
8 changed files with 26 additions and 10 deletions
|
@ -470,8 +470,14 @@ class PerDestinationQueue:
|
|||
# servers, but the remote will correctly deduplicate them and
|
||||
# handle it only once.
|
||||
|
||||
# Step 1, fetch the current extremities
|
||||
extrems = await self._store.get_prev_events_for_room(pdu.room_id)
|
||||
# Step 1, fetch some of the current extremities
|
||||
# For partial state rooms, we intentionally restrict ourselves
|
||||
# to only using our own events here, since we shouldn't divulge
|
||||
# other servers' events to servers which we can't know,
|
||||
# with certainty, whether they are in the room or not.
|
||||
extrems = await self._store.get_prev_events_for_creating_event_in_room(
|
||||
pdu.room_id
|
||||
)
|
||||
|
||||
if pdu.event_id in extrems:
|
||||
# If the event is in the extremities, then great! We can just
|
||||
|
|
|
@ -1121,7 +1121,11 @@ class EventCreationHandler:
|
|||
len(prev_event_ids),
|
||||
)
|
||||
else:
|
||||
prev_event_ids = await self.store.get_prev_events_for_room(builder.room_id)
|
||||
prev_event_ids = (
|
||||
await self.store.get_prev_events_for_creating_event_in_room(
|
||||
builder.room_id
|
||||
)
|
||||
)
|
||||
|
||||
# Do a quick sanity check here, rather than waiting until we've created the
|
||||
# event and then try to auth it (which fails with a somewhat confusing "No
|
||||
|
@ -2061,7 +2065,9 @@ class EventCreationHandler:
|
|||
|
||||
# modules can send new state events, so we re-calculate the auth events just in
|
||||
# case.
|
||||
prev_event_ids = await self.store.get_prev_events_for_room(builder.room_id)
|
||||
prev_event_ids = await self.store.get_prev_events_for_creating_event_in_room(
|
||||
builder.room_id
|
||||
)
|
||||
|
||||
event = await builder.build(
|
||||
prev_event_ids=prev_event_ids,
|
||||
|
|
|
@ -1062,7 +1062,9 @@ class EventFederationWorkerStore(SignatureWorkerStore, EventsWorkerStore, SQLBas
|
|||
|
||||
return min_depth_event_id, current_min_depth
|
||||
|
||||
async def get_prev_events_for_creating_event_in_room(self, room_id: str) -> List[str]:
|
||||
async def get_prev_events_for_creating_event_in_room(
|
||||
self, room_id: str
|
||||
) -> List[str]:
|
||||
"""
|
||||
Gets up to 10 event IDs which are suitable for use as `prev_events`
|
||||
when creating an event in the given room.
|
||||
|
|
|
@ -249,7 +249,7 @@ class SyncTestCase(tests.unittest.HomeserverTestCase):
|
|||
# precede the join.
|
||||
mocked_get_prev_events = patch.object(
|
||||
self.hs.get_datastores().main,
|
||||
"get_prev_events_for_room",
|
||||
"get_prev_events_for_creating_event_in_room",
|
||||
new_callable=MagicMock,
|
||||
return_value=make_awaitable([last_room_creation_event_id]),
|
||||
)
|
||||
|
|
|
@ -515,7 +515,7 @@ class EventChainBackgroundUpdateTestCase(HomeserverTestCase):
|
|||
# Create a fork in the DAG with different events.
|
||||
event_handler = self.hs.get_event_creation_handler()
|
||||
latest_event_ids = self.get_success(
|
||||
self.store.get_prev_events_for_room(room_id)
|
||||
self.store.get_prev_events_for_full_state_room(room_id)
|
||||
)
|
||||
event, context = self.get_success(
|
||||
event_handler.create_event(
|
||||
|
|
|
@ -77,7 +77,7 @@ class EventFederationWorkerStoreTestCase(tests.unittest.HomeserverTestCase):
|
|||
)
|
||||
|
||||
# this should get the last ten
|
||||
r = self.get_success(self.store.get_prev_events_for_room(room_id))
|
||||
r = self.get_success(self.store.get_prev_events_for_full_state_room(room_id))
|
||||
self.assertEqual(10, len(r))
|
||||
for i in range(0, 10):
|
||||
self.assertEqual("$event_%i:local" % (19 - i), r[i])
|
||||
|
|
|
@ -81,7 +81,7 @@ class ExtremPruneTestCase(HomeserverTestCase):
|
|||
def assert_extremities(self, expected_extremities):
|
||||
"""Assert the current extremities for the room"""
|
||||
extremities = self.get_success(
|
||||
self.store.get_prev_events_for_room(self.room_id)
|
||||
self.store.get_prev_events_for_full_state_room(self.room_id)
|
||||
)
|
||||
self.assertCountEqual(extremities, expected_extremities)
|
||||
|
||||
|
|
|
@ -96,7 +96,9 @@ class EventSearchInsertionTest(HomeserverTestCase):
|
|||
# Construct a message with a numeric body to be received over federation
|
||||
# The message can't be sent using the client API, since Synapse's event
|
||||
# validation will reject it.
|
||||
prev_event_ids = self.get_success(store.get_prev_events_for_room(room_id))
|
||||
prev_event_ids = self.get_success(
|
||||
store.get_prev_events_for_full_state_room(room_id)
|
||||
)
|
||||
prev_event = self.get_success(store.get_event(prev_event_ids[0]))
|
||||
prev_state_map = self.get_success(
|
||||
self.hs.get_storage_controllers().state.get_state_ids_for_event(
|
||||
|
|
Loading…
Reference in a new issue