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

Commit

Permalink
Remove the limited flag.
Browse files Browse the repository at this point in the history
  • Loading branch information
clokep committed Mar 30, 2022
1 parent 13324cf commit 8305571
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 34 deletions.
4 changes: 2 additions & 2 deletions synapse/handlers/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ async def _get_bundled_aggregation_for_event(
# while others need more processing during serialization.
aggregations = BundledAggregations()

annotations, limited = await self._main_store.get_aggregation_groups_for_event(
annotations = await self._main_store.get_aggregation_groups_for_event(
event_id, room_id
)
if annotations:
aggregations.annotations = {"chunk": annotations, "limited": limited}
aggregations.annotations = {"chunk": annotations}

references = await self._main_store.get_relations_for_event(
event_id, event, room_id, RelationTypes.REFERENCE, direction="f"
Expand Down
22 changes: 8 additions & 14 deletions synapse/storage/databases/main/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ async def event_is_target_of_relation(self, parent_id: str) -> bool:
@cached(tree=True)
async def get_aggregation_groups_for_event(
self, event_id: str, room_id: str, limit: int = 5
) -> Tuple[List[JsonDict], bool]:
) -> List[JsonDict]:
"""Get a list of annotations on the event, grouped by event type and
aggregation key, sorted by count.
Expand All @@ -264,18 +264,15 @@ async def get_aggregation_groups_for_event(
limit: Only fetch the `limit` groups.
Returns:
A tuple of:
A list of groups of annotations that match. Each row is a dict with
`type`, `key` and `count` fields.
A boolean indicating if the result is limited (i.e. if there are
additional results to return).
A list of groups of annotations that match. Each row is a dict with
`type`, `key` and `count` fields.
"""

where_args: List[Union[str, int]] = [
where_args = [
event_id,
room_id,
RelationTypes.ANNOTATION,
limit,
]

sql = """
Expand All @@ -290,13 +287,10 @@ async def get_aggregation_groups_for_event(

def _get_aggregation_groups_for_event_txn(
txn: LoggingTransaction,
) -> Tuple[List[JsonDict], bool]:
txn.execute(sql, where_args + [limit + 1])

events = [{"type": row[0], "key": row[1], "count": row[2]} for row in txn]
limited = len(events) > limit
) -> List[JsonDict]:
txn.execute(sql, where_args)

return events[:limit], limited
return [{"type": row[0], "key": row[1], "count": row[2]} for row in txn]

return await self.db_pool.runInteraction(
"get_aggregation_groups_for_event", _get_aggregation_groups_for_event_txn
Expand Down
24 changes: 6 additions & 18 deletions tests/rest/client/test_relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -984,8 +984,7 @@ def assert_annotations(bundled_aggregations: JsonDict) -> None:
"chunk": [
{"type": "m.reaction", "key": "a", "count": 2},
{"type": "m.reaction", "key": "b", "count": 1},
],
"limited": False,
]
},
bundled_aggregations,
)
Expand Down Expand Up @@ -1081,8 +1080,7 @@ def test_aggregation_get_event_for_thread(self) -> None:
channel.json_body["unsigned"].get("m.relations"),
{
RelationTypes.ANNOTATION: {
"chunk": [{"count": 1, "key": "a", "type": "m.reaction"}],
"limited": False,
"chunk": [{"count": 1, "key": "a", "type": "m.reaction"}]
},
},
)
Expand All @@ -1101,8 +1099,7 @@ def test_aggregation_get_event_for_thread(self) -> None:
thread_message["unsigned"].get("m.relations"),
{
RelationTypes.ANNOTATION: {
"chunk": [{"count": 1, "key": "a", "type": "m.reaction"}],
"limited": False,
"chunk": [{"count": 1, "key": "a", "type": "m.reaction"}]
},
},
)
Expand Down Expand Up @@ -1262,10 +1259,7 @@ def test_redact_relation_annotation(self) -> None:
self.assertCountEqual(event_ids, [to_redact_event_id, unredacted_event_id])
self.assertEquals(
relations["m.annotation"],
{
"chunk": [{"type": "m.reaction", "key": "a", "count": 2}],
"limited": False,
},
{"chunk": [{"type": "m.reaction", "key": "a", "count": 2}]},
)

# Redact one of the reactions.
Expand All @@ -1277,10 +1271,7 @@ def test_redact_relation_annotation(self) -> None:
self.assertEquals(event_ids, [unredacted_event_id])
self.assertEquals(
relations["m.annotation"],
{
"chunk": [{"type": "m.reaction", "key": "a", "count": 1}],
"limited": False,
},
{"chunk": [{"type": "m.reaction", "key": "a", "count": 1}]},
)

def test_redact_relation_thread(self) -> None:
Expand Down Expand Up @@ -1397,10 +1388,7 @@ def test_redact_parent_annotation(self) -> None:
self.assertEquals(event_ids, [related_event_id])
self.assertEquals(
relations["m.annotation"],
{
"chunk": [{"type": "m.reaction", "key": "👍", "count": 1}],
"limited": False,
},
{"chunk": [{"type": "m.reaction", "key": "👍", "count": 1}]},
)

@unittest.override_config({"experimental_features": {"msc3440_enabled": True}})
Expand Down

0 comments on commit 8305571

Please sign in to comment.