summary refs log tree commit diff
diff options
context:
space:
mode:
authorPatrick Cloke <patrickc@matrix.org>2022-12-15 07:48:48 -0500
committerPatrick Cloke <patrickc@matrix.org>2023-05-17 14:26:01 -0400
commite55ad9b6cfa09f62ac141a0ab06bd6d41f038ced (patch)
tree2e57e63488da3bde94f54d62cf560c64f3aab7d7
parentNewsfragment (diff)
downloadsynapse-e55ad9b6cfa09f62ac141a0ab06bd6d41f038ced.tar.xz
Clean-up more references to relations store.
-rw-r--r--synapse/api/filtering.py2
-rw-r--r--synapse/handlers/message.py8
-rw-r--r--synapse/push/bulk_push_rule_evaluator.py2
-rw-r--r--synapse/rest/client/receipts.py8
-rw-r--r--synapse/storage/databases/main/__init__.py4
-rw-r--r--synapse/storage/databases/main/events.py16
6 files changed, 25 insertions, 15 deletions
diff --git a/synapse/api/filtering.py b/synapse/api/filtering.py
index de7c56bc0f..4c60905b31 100644
--- a/synapse/api/filtering.py
+++ b/synapse/api/filtering.py
@@ -507,7 +507,7 @@ class Filter:
         # The event IDs to check, mypy doesn't understand the isinstance check.
         event_ids = [event.event_id for event in events if isinstance(event, EventBase)]  # type: ignore[attr-defined]
         event_ids_to_keep = set(
-            await self._store.events_have_relations(
+            await self._store.relations.events_have_relations(
                 event_ids, self.related_by_senders, self.related_by_rel_types
             )
         )
diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py
index 0b61c2272b..adc4702765 100644
--- a/synapse/handlers/message.py
+++ b/synapse/handlers/message.py
@@ -1361,7 +1361,9 @@ class EventCreationHandler:
         else:
             # There must be some reason that the client knows the event exists,
             # see if there are existing relations. If so, assume everything is fine.
-            if not await self.store.event_is_target_of_relation(relation.parent_id):
+            if not await self.store.relations.event_is_target_of_relation(
+                relation.parent_id
+            ):
                 # Otherwise, the client can't know about the parent event!
                 raise SynapseError(400, "Can't send relation to unknown event")
 
@@ -1377,7 +1379,7 @@ class EventCreationHandler:
             if len(aggregation_key) > 500:
                 raise SynapseError(400, "Aggregation key is too long")
 
-            already_exists = await self.store.has_user_annotated_event(
+            already_exists = await self.store.relations.has_user_annotated_event(
                 relation.parent_id, event.type, aggregation_key, event.sender
             )
             if already_exists:
@@ -1389,7 +1391,7 @@ class EventCreationHandler:
 
         # Don't attempt to start a thread if the parent event is a relation.
         elif relation.rel_type == RelationTypes.THREAD:
-            if await self.store.event_includes_relation(relation.parent_id):
+            if await self.store.relations.event_includes_relation(relation.parent_id):
                 raise SynapseError(
                     400, "Cannot start threads from an event with a relation"
                 )
diff --git a/synapse/push/bulk_push_rule_evaluator.py b/synapse/push/bulk_push_rule_evaluator.py
index 320084f5f5..5e6d594a30 100644
--- a/synapse/push/bulk_push_rule_evaluator.py
+++ b/synapse/push/bulk_push_rule_evaluator.py
@@ -368,7 +368,7 @@ class BulkPushRuleEvaluator:
             else:
                 # Since the event has not yet been persisted we check whether
                 # the parent is part of a thread.
-                thread_id = await self.store.get_thread_id(relation.parent_id)
+                thread_id = await self.store.relations.get_thread_id(relation.parent_id)
 
         related_events = await self._related_events(event)
 
diff --git a/synapse/rest/client/receipts.py b/synapse/rest/client/receipts.py
index 316e7b9982..79914e1b9d 100644
--- a/synapse/rest/client/receipts.py
+++ b/synapse/rest/client/receipts.py
@@ -147,11 +147,15 @@ class ReceiptRestServlet(RestServlet):
         # If the receipt is on the main timeline, it is enough to check whether
         # the event is directly related to a thread.
         if thread_id == MAIN_TIMELINE:
-            return MAIN_TIMELINE == await self._main_store.get_thread_id(event_id)
+            return MAIN_TIMELINE == await self._main_store.relations.get_thread_id(
+                event_id
+            )
 
         # Otherwise, check if the event is directly part of a thread, or is the
         # root message (or related to the root message) of a thread.
-        return thread_id == await self._main_store.get_thread_id_for_receipts(event_id)
+        return thread_id == await self._main_store.relations.get_thread_id_for_receipts(
+            event_id
+        )
 
 
 def register_servlets(hs: "HomeServer", http_server: HttpServer) -> None:
diff --git a/synapse/storage/databases/main/__init__.py b/synapse/storage/databases/main/__init__.py
index eb035591bf..867fd84179 100644
--- a/synapse/storage/databases/main/__init__.py
+++ b/synapse/storage/databases/main/__init__.py
@@ -16,16 +16,16 @@
 
 import logging
 import re
-from typing import TYPE_CHECKING, Any, List, Match, Optional, Tuple, Type, cast
+from typing import TYPE_CHECKING, List, Match, Optional, Tuple, Type, cast
 
 from synapse.api.constants import Direction
 from synapse.config.homeserver import HomeServerConfig
+from synapse.storage._base import SQLBaseStore
 from synapse.storage.database import (
     DatabasePool,
     LoggingDatabaseConnection,
     LoggingTransaction,
 )
-from synapse.storage._base import SQLBaseStore
 from synapse.storage.databases.main.stats import UserSortOrder
 from synapse.storage.engines import BaseDatabaseEngine
 from synapse.storage.types import Cursor
diff --git a/synapse/storage/databases/main/events.py b/synapse/storage/databases/main/events.py
index e2e6eb479f..eae5844330 100644
--- a/synapse/storage/databases/main/events.py
+++ b/synapse/storage/databases/main/events.py
@@ -2072,25 +2072,29 @@ class PersistEventsStore:
 
         # Any relation information for the related event must be cleared.
         self.store._invalidate_cache_and_stream(
-            txn, self.store.get_relations_for_event, (redacted_relates_to,)
+            txn, self.store.relations.get_relations_for_event, (redacted_relates_to,)
         )
         if rel_type == RelationTypes.REFERENCE:
             self.store._invalidate_cache_and_stream(
-                txn, self.store.get_references_for_event, (redacted_relates_to,)
+                txn,
+                self.store.relations.get_references_for_event,
+                (redacted_relates_to,),
             )
         if rel_type == RelationTypes.REPLACE:
             self.store._invalidate_cache_and_stream(
-                txn, self.store.get_applicable_edit, (redacted_relates_to,)
+                txn, self.store.relations.get_applicable_edit, (redacted_relates_to,)
             )
         if rel_type == RelationTypes.THREAD:
             self.store._invalidate_cache_and_stream(
-                txn, self.store.get_thread_summary, (redacted_relates_to,)
+                txn, self.store.relations.get_thread_summary, (redacted_relates_to,)
             )
             self.store._invalidate_cache_and_stream(
-                txn, self.store.get_thread_participated, (redacted_relates_to,)
+                txn,
+                self.store.relations.get_thread_participated,
+                (redacted_relates_to,),
             )
             self.store._invalidate_cache_and_stream(
-                txn, self.store.get_threads, (room_id,)
+                txn, self.store.relations.get_threads, (room_id,)
             )
 
             # Find the new latest event in the thread.