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

Commit

Permalink
Inline a helper used only once.
Browse files Browse the repository at this point in the history
  • Loading branch information
clokep committed Nov 21, 2022
1 parent 6be806b commit ef8a9d7
Showing 1 changed file with 11 additions and 41 deletions.
52 changes: 11 additions & 41 deletions synapse/handlers/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,40 +172,6 @@ async def get_relations(

return return_value

async def get_relations_for_event(
self,
event_id: str,
event: EventBase,
room_id: str,
relation_type: str,
ignored_users: FrozenSet[str] = frozenset(),
) -> List[_RelatedEvent]:
"""Get a list of events which relate to an event, ordered by topological ordering.
Args:
event_id: Fetch events that relate to this event ID.
event: The matching EventBase to event_id.
room_id: The room the event belongs to.
relation_type: The type of relation.
ignored_users: The users ignored by the requesting user.
Returns:
List of event IDs that match relations requested. The rows are of
the form `{"event_id": "..."}`.
"""

# Call the underlying storage method, which is cached.
related_events, _ = await self._main_store.get_relations_for_event(
event_id, event, room_id, relation_type, direction="f"
)

# Filter out ignored users and convert to the expected format.
related_events = [
event for event in related_events if event.sender not in ignored_users
]

return related_events

async def redact_events_related_to(
self,
requester: Requester,
Expand Down Expand Up @@ -443,14 +409,18 @@ async def _get_threads_for_events(
if event is None:
continue

potential_events = await self.get_relations_for_event(
event_id,
event,
room_id,
RelationTypes.THREAD,
ignored_users,
# Attempt to find another event to use as the latest event.
potential_events, _ = await self._main_store.get_relations_for_event(
event_id, event, room_id, RelationTypes.THREAD, direction="f"
)

# Filter out ignored users.
potential_events = [
event
for event in potential_events
if event.sender not in ignored_users
]

# If all found events are from ignored users, do not include
# a summary of the thread.
if not potential_events:
Expand Down Expand Up @@ -620,7 +590,7 @@ async def get_threads(
room_id, requester, allow_departed_users=True
)

# Note that ignored users are not passed into get_relations_for_event
# Note that ignored users are not passed into get_threads
# below. Ignored users are handled in filter_events_for_client (and by
# not passing them in here we should get a better cache hit rate).
thread_roots, next_batch = await self._main_store.get_threads(
Expand Down

0 comments on commit ef8a9d7

Please sign in to comment.