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

Add a class UnpersistedEventContext to allow for the batching up of storing state groups #14675

Merged
merged 32 commits into from
Feb 9, 2023
Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
286469f
add class UnpersistedEventContext
H-Shay Dec 13, 2022
6322dac
modify create new client event to create unpersistedeventcontexts
H-Shay Dec 13, 2022
54fa7f0
persist event contexts after creation
H-Shay Dec 13, 2022
d23d1be
fix tests to persist unpersisted event contexts
H-Shay Dec 13, 2022
b483243
cleanup
H-Shay Dec 13, 2022
c008b6f
misc lints + cleanup
H-Shay Dec 13, 2022
c6ef7bb
Merge branch 'develop' into shay/rework_event_context
H-Shay Dec 13, 2022
0f07c0e
changelog + fix comments
H-Shay Dec 13, 2022
a66cc71
Merge branch 'shay/rework_event_context' of https://github.com/matrix…
H-Shay Dec 13, 2022
78a71ed
lints
H-Shay Dec 13, 2022
6321576
fix batch insertion?
H-Shay Dec 14, 2022
d6454ce
reduce redundant calculation
H-Shay Dec 14, 2022
8b99436
add unpersisted event classes
H-Shay Jan 9, 2023
1668fd2
rework compute_event_context, split into function that returns unpers…
H-Shay Jan 9, 2023
7e494fc
use calculate_context_info to create unpersisted event contexts
H-Shay Jan 9, 2023
61c8de0
update typing
H-Shay Jan 9, 2023
ed2e305
Merge branch 'develop' into shay/rework_event_context
H-Shay Jan 9, 2023
f7eafcf
$%#^&*
H-Shay Jan 10, 2023
0402917
black
H-Shay Jan 10, 2023
373e331
fix comments and consolidate classes, use attr.s for class
H-Shay Jan 12, 2023
408fa21
requested changes
H-Shay Jan 12, 2023
345d746
lint
H-Shay Jan 12, 2023
b9ee9d3
Merge branch 'develop' into shay/rework_event_context
H-Shay Jan 20, 2023
cdce9a2
requested changes
H-Shay Jan 20, 2023
b69a87c
requested changes
H-Shay Jan 23, 2023
8830c94
refactor to be stupidly explicit
H-Shay Jan 26, 2023
d4c380d
Merge branch 'develop' into shay/rework_event_context
H-Shay Jan 26, 2023
f439b23
Merge branch 'develop' into shay/rework_event_context
erikjohnston Feb 7, 2023
3614ed0
clearer renaming and flow
H-Shay Feb 8, 2023
a0bcc0a
Merge branch 'shay/rework_event_context' of https://github.com/matrix…
H-Shay Feb 8, 2023
427d007
make partial state non-optional
H-Shay Feb 8, 2023
c3bdb6e
update docstrings
H-Shay Feb 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 34 additions & 20 deletions synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
from synapse.crypto.event_signing import compute_event_signature
from synapse.event_auth import validate_event_for_room_version
from synapse.events import EventBase
from synapse.events.snapshot import EventContext
from synapse.events.snapshot import EventContext, UnpersistedEventContext
from synapse.events.validator import EventValidator
from synapse.federation.federation_client import InvalidResponseError
from synapse.http.servlet import assert_params_in_dict
Expand Down Expand Up @@ -1123,7 +1123,7 @@ async def on_make_leave_request(
},
)

event, context = await self.event_creation_handler.create_new_client_event(
event, _ = await self.event_creation_handler.create_new_client_event(
DMRobertson marked this conversation as resolved.
Show resolved Hide resolved
builder=builder
)

Expand Down Expand Up @@ -1173,12 +1173,14 @@ async def on_make_knock_request(
},
)

event, context = await self.event_creation_handler.create_new_client_event(
builder=builder
)

(
event,
unpersisted_context,
) = await self.event_creation_handler.create_new_client_event(builder=builder)

event_allowed, _ = await self.third_party_event_rules.check_event_allowed(
event, context
event, unpersisted_context
)
if not event_allowed:
logger.warning("Creation of knock %s forbidden by third-party rules", event)
Expand Down Expand Up @@ -1343,14 +1345,19 @@ async def exchange_third_party_invite(
)

EventValidator().validate_builder(builder)
event, context = await self.event_creation_handler.create_new_client_event(
event, unpersisted_context = await self.event_creation_handler.create_new_client_event(
builder=builder
)

event, context = await self.add_display_name_to_third_party_invite(
room_version_obj, event_dict, event, context
(
event,
unpersisted_context,
) = await self.add_display_name_to_third_party_invite(
room_version_obj, event_dict, event, unpersisted_context
)

context = await unpersisted_context.persist(event)

EventValidator().validate_new(event, self.config)

# We need to tell the transaction queue to send this out, even
Expand Down Expand Up @@ -1400,13 +1407,17 @@ async def on_exchange_third_party_invite_request(
room_version_obj, event_dict
)

event, context = await self.event_creation_handler.create_new_client_event(
builder=builder
)
event, context = await self.add_display_name_to_third_party_invite(
room_version_obj, event_dict, event, context
(
event,
unpersisted_context,
) = await self.event_creation_handler.create_new_client_event(builder=builder)

event, unpersisted_context = await self.add_display_name_to_third_party_invite(
room_version_obj, event_dict, event, unpersisted_context
)

context = await unpersisted_context.persist(event)

try:
validate_event_for_room_version(event)
await self._event_auth_handler.check_auth_rules_from_context(event)
Expand All @@ -1428,8 +1439,8 @@ async def add_display_name_to_third_party_invite(
room_version_obj: RoomVersion,
event_dict: JsonDict,
event: EventBase,
context: EventContext,
) -> Tuple[EventBase, EventContext]:
context: UnpersistedEventContext,
) -> Tuple[EventBase, UnpersistedEventContext]:
key = (
EventTypes.ThirdPartyInvite,
event.content["third_party_invite"]["signed"]["token"],
Expand Down Expand Up @@ -1463,11 +1474,14 @@ async def add_display_name_to_third_party_invite(
room_version_obj, event_dict
)
EventValidator().validate_builder(builder)
event, context = await self.event_creation_handler.create_new_client_event(
builder=builder
)

(
event,
unpersisted_context,
) = await self.event_creation_handler.create_new_client_event(builder=builder)

EventValidator().validate_new(event, self.config)
return event, context
return event, unpersisted_context

async def _check_signature(self, event: EventBase, context: EventContext) -> None:
"""
Expand Down