Add cache to relations

This commit is contained in:
Erik Johnston 2019-05-16 09:56:12 +01:00
parent a0603523d2
commit 33453419b0

View File

@ -21,6 +21,7 @@ from synapse.api.constants import RelationTypes
from synapse.api.errors import SynapseError from synapse.api.errors import SynapseError
from synapse.storage._base import SQLBaseStore from synapse.storage._base import SQLBaseStore
from synapse.storage.stream import generate_pagination_where_clause from synapse.storage.stream import generate_pagination_where_clause
from synapse.util.caches.descriptors import cached
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -109,6 +110,7 @@ class AggregationPaginationToken(object):
class RelationsStore(SQLBaseStore): class RelationsStore(SQLBaseStore):
@cached(tree=True)
def get_relations_for_event( def get_relations_for_event(
self, self,
event_id, event_id,
@ -216,6 +218,7 @@ class RelationsStore(SQLBaseStore):
"get_recent_references_for_event", _get_recent_references_for_event_txn "get_recent_references_for_event", _get_recent_references_for_event_txn
) )
@cached(tree=True)
def get_aggregation_groups_for_event( def get_aggregation_groups_for_event(
self, self,
event_id, event_id,
@ -353,3 +356,8 @@ class RelationsStore(SQLBaseStore):
"aggregation_key": aggregation_key, "aggregation_key": aggregation_key,
}, },
) )
txn.call_after(self.get_relations_for_event.invalidate_many, (parent_id,))
txn.call_after(
self.get_aggregation_groups_for_event.invalidate_many, (parent_id,)
)