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

Commit

Permalink
Fetch event edits in groups.
Browse files Browse the repository at this point in the history
  • Loading branch information
clokep committed Dec 29, 2021
1 parent 9804abc commit c2c9e66
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions synapse/storage/databases/main/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from typing import (
TYPE_CHECKING,
Any,
Collection,
Dict,
Iterable,
List,
Expand All @@ -28,7 +29,7 @@
import attr
from frozendict import frozendict

from synapse.api.constants import EventTypes, RelationTypes
from synapse.api.constants import RelationTypes
from synapse.events import EventBase
from synapse.storage._base import SQLBaseStore
from synapse.storage.database import (
Expand Down Expand Up @@ -631,14 +632,6 @@ async def _get_bundled_aggregation_for_event(
if references.chunk:
aggregations[RelationTypes.REFERENCE] = references.to_dict()

edit = None
if event.type == EventTypes.Message:
edits = await self._get_applicable_edits([event_id])
edit = edits.get(event_id)

if edit:
aggregations[RelationTypes.REPLACE] = edit

# If this event is the start of a thread, include a summary of the replies.
if self._msc3440_enabled:
(
Expand All @@ -656,7 +649,7 @@ async def _get_bundled_aggregation_for_event(
return aggregations

async def get_bundled_aggregations(
self, events: Iterable[EventBase]
self, events: Collection[EventBase]
) -> Dict[str, Dict[str, Any]]:
"""Generate bundled aggregations for events.
Expand All @@ -671,12 +664,21 @@ async def get_bundled_aggregations(
if not self._msc1849_enabled:
return {}

# TODO Parallelize.
results = {}
# event ID -> bundled aggregation in non-serialized form.
results: Dict[str, Dict[str, Any]] = {}

event_ids = [event.event_id for event in events]

# Fetch any edits.
edits = await self._get_applicable_edits(event_ids)
for event_id, edit in edits.items():
results.setdefault(event_id, {})[RelationTypes.REPLACE] = edit

# Fetch other relations per event.
for event in events:
event_result = await self._get_bundled_aggregation_for_event(event)
if event_result is not None:
results[event.event_id] = event_result
results.setdefault(event.event_id, {}).update(event_result)

return results

Expand Down

0 comments on commit c2c9e66

Please sign in to comment.