Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions changelog.d/19527.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Avoid re-computing the event ID when cloning events.
10 changes: 9 additions & 1 deletion synapse/events/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
from synapse.logging.opentracing import SynapseTags, set_tag, trace
from synapse.types import JsonDict, Requester

from . import EventBase, StrippedStateEvent, make_event_from_dict
from . import EventBase, FrozenEventV2, StrippedStateEvent, make_event_from_dict

if TYPE_CHECKING:
from synapse.handlers.relations import BundledAggregations
Expand Down Expand Up @@ -109,6 +109,14 @@ def clone_event(event: EventBase) -> EventBase:
event.get_dict(), event.room_version, event.internal_metadata.get_dict()
)

# Starting FrozenEventV2, the event ID is an (expensive) hash of the event. This is
# lazily computed when we get the FrozenEventV2.event_id property, then cached in
# _event_id field. Later FrozenEvent formats all inherit from FrozenEventV2, so we
# can use the same logic here.
if isinstance(event, FrozenEventV2) and isinstance(new_event, FrozenEventV2):
# If we already pre-computed the event ID, use it.
new_event._event_id = event._event_id

# Copy the bits of `internal_metadata` that aren't returned by `get_dict`.
new_event.internal_metadata.stream_ordering = (
event.internal_metadata.stream_ordering
Expand Down
Loading