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

Fetch edits for multiple events in a single query #11660

Merged
merged 16 commits into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 1 addition & 3 deletions synapse/storage/databases/main/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -1783,9 +1783,7 @@ def _handle_event_relations(
)

if rel_type == RelationTypes.REPLACE:
txn.call_after(
self.store.get_applicable_edit.invalidate, (parent_id, event.room_id)
)
txn.call_after(self.store.get_applicable_edit.invalidate, (parent_id,))

if rel_type == RelationTypes.THREAD:
txn.call_after(
Expand Down
11 changes: 4 additions & 7 deletions synapse/storage/databases/main/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,17 +326,14 @@ def _get_aggregation_groups_for_event_txn(
)

@cached()
async def get_applicable_edit(
self, event_id: str, room_id: str
) -> Optional[EventBase]:
async def get_applicable_edit(self, event_id: str) -> Optional[EventBase]:
"""Get the most recent edit (if any) that has happened for the given
event.

Correctly handles checking whether edits were allowed to happen.

Args:
event_id: The original event ID
room_id: The original event's room ID

Returns:
The most recent edit, if any.
Expand All @@ -355,17 +352,17 @@ async def get_applicable_edit(
original.event_id = relates_to_id
AND edit.type = original.type
AND edit.sender = original.sender
AND edit.room_id = original.room_id
DMRobertson marked this conversation as resolved.
Show resolved Hide resolved
WHERE
relates_to_id = ?
AND relation_type = ?
AND edit.room_id = ?
AND edit.type = 'm.room.message'
ORDER by edit.origin_server_ts DESC, edit.event_id DESC
LIMIT 1
"""

def _get_applicable_edit_txn(txn: LoggingTransaction) -> Optional[str]:
txn.execute(sql, (event_id, RelationTypes.REPLACE, room_id))
txn.execute(sql, (event_id, RelationTypes.REPLACE))
row = txn.fetchone()
if row:
return row[0]
Expand Down Expand Up @@ -591,7 +588,7 @@ async def _get_bundled_aggregation_for_event(

edit = None
if event.type == EventTypes.Message:
edit = await self.get_applicable_edit(event_id, room_id)
edit = await self.get_applicable_edit(event_id)

if edit:
aggregations[RelationTypes.REPLACE] = edit
Expand Down