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

Commit

Permalink
Use uncached_args parameter instead of num_args.
Browse files Browse the repository at this point in the history
  • Loading branch information
clokep committed Mar 9, 2022
1 parent ad0a3a6 commit ecbc2d9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
4 changes: 2 additions & 2 deletions synapse/rest/client/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ async def on_GET(

pagination_chunk = await self.store.get_relations_for_event(
event_id=parent_id,
event=event,
room_id=room_id,
relation_type=relation_type,
event_type=event_type,
limit=limit,
direction=direction,
from_token=from_token,
to_token=to_token,
event=event,
)

events = await self.store.get_events_as_list(
Expand Down Expand Up @@ -288,14 +288,14 @@ async def on_GET(

result = await self.store.get_relations_for_event(
event_id=parent_id,
event=event,
room_id=room_id,
relation_type=relation_type,
event_type=event_type,
aggregation_key=key,
limit=limit,
from_token=from_token,
to_token=to_token,
event=event,
)

events = await self.store.get_events_as_list(
Expand Down
11 changes: 5 additions & 6 deletions synapse/storage/databases/main/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@ def __init__(

self._msc3440_enabled = hs.config.experimental.msc3440_enabled

@cached(num_args=9, tree=True)
@cached(uncached_args=("event",), tree=True)
async def get_relations_for_event(
self,
event_id: str,
event: EventBase,
room_id: str,
relation_type: Optional[str] = None,
event_type: Optional[str] = None,
Expand All @@ -103,12 +104,12 @@ async def get_relations_for_event(
direction: str = "b",
from_token: Optional[StreamToken] = None,
to_token: Optional[StreamToken] = None,
event: Optional[EventBase] = None,
) -> PaginationChunk:
"""Get a list of relations for 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: Only fetch events with this relation type, if given.
event_type: Only fetch events with this event type, if given.
Expand All @@ -118,15 +119,13 @@ async def get_relations_for_event(
oldest first (`"f"`).
from_token: Fetch rows from the given token, or from the start if None.
to_token: Fetch rows up to the given token, or up to the end if None.
event: The matching EventBase to event_id. This *must* be provided.
Returns:
List of event IDs that match relations requested. The rows are of
the form `{"event_id": "..."}`.
"""
# We don't use `event_id`, its there so that we can cache based on
# We don't use `event_id`, it's there so that we can cache based on
# it. The `event_id` must match the `event.event_id`.
assert event is not None
assert event.event_id == event_id

where_clause = ["relates_to_id = ?", "room_id = ?"]
Expand Down Expand Up @@ -786,7 +785,7 @@ async def _get_bundled_aggregation_for_event(
)

references = await self.get_relations_for_event(
event_id, room_id, RelationTypes.REFERENCE, direction="f", event=event
event_id, event, room_id, RelationTypes.REFERENCE, direction="f"
)
if references.chunk:
aggregations.references = await references.to_dict(cast("DataStore", self))
Expand Down

0 comments on commit ecbc2d9

Please sign in to comment.