From 830557189c439b4b0f9e2da32452777586e616b1 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Wed, 30 Mar 2022 09:50:36 -0400 Subject: [PATCH] Remove the limited flag. --- synapse/handlers/relations.py | 4 ++-- synapse/storage/databases/main/relations.py | 22 +++++++------------ tests/rest/client/test_relations.py | 24 ++++++--------------- 3 files changed, 16 insertions(+), 34 deletions(-) diff --git a/synapse/handlers/relations.py b/synapse/handlers/relations.py index 8d8fe42aad5d..b9497ff3f3ba 100644 --- a/synapse/handlers/relations.py +++ b/synapse/handlers/relations.py @@ -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" diff --git a/synapse/storage/databases/main/relations.py b/synapse/storage/databases/main/relations.py index 66ee71cc8ee1..dc3c316948b6 100644 --- a/synapse/storage/databases/main/relations.py +++ b/synapse/storage/databases/main/relations.py @@ -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. @@ -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 = """ @@ -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 diff --git a/tests/rest/client/test_relations.py b/tests/rest/client/test_relations.py index 757d17b9e9de..419eef166ac4 100644 --- a/tests/rest/client/test_relations.py +++ b/tests/rest/client/test_relations.py @@ -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, ) @@ -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"}] }, }, ) @@ -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"}] }, }, ) @@ -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. @@ -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: @@ -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}})