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

Commit

Permalink
Properly redact caches.
Browse files Browse the repository at this point in the history
  • Loading branch information
clokep committed Mar 4, 2022
1 parent 7f3593c commit 6687bbd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
6 changes: 5 additions & 1 deletion synapse/storage/databases/main/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,11 @@ def _invalidate_caches_for_event(
self.get_invited_rooms_for_local_user.invalidate((state_key,))

if relates_to:
self._invalidate_relations_for_event(relates_to)
self.get_relations_for_event.invalidate((event_id,))
self.get_aggregation_groups_for_event.invalidate((event_id,))
self.get_applicable_edit.invalidate((event_id,))
self.get_thread_summary.invalidate((event_id,))
self.get_thread_participated.invalidate((event_id,))

async def invalidate_cache_and_stream(self, cache_name: str, keys: Tuple[Any, ...]):
"""Invalidates the cache and adds it to the cache stream so slaves
Expand Down
16 changes: 15 additions & 1 deletion synapse/storage/databases/main/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -1964,7 +1964,21 @@ def _handle_redact_relations(
)
# Any relation information for the related events must be cleared.
if relates_to is not None:
txn.call_after(self.store._invalidate_relations_for_event, relates_to)
self.store._invalidate_cache_and_stream(
txn, self.store.get_relations_for_event, (relates_to,)
)
self.store._invalidate_cache_and_stream(
txn, self.store.get_aggregation_groups_for_event, (relates_to,)
)
self.store._invalidate_cache_and_stream(
txn, self.store.get_applicable_edit, (relates_to,)
)
self.store._invalidate_cache_and_stream(
txn, self.store.get_thread_summary, (relates_to,)
)
self.store._invalidate_cache_and_stream(
txn, self.store.get_thread_participated, (relates_to,)
)

self.db_pool.simple_delete_txn(
txn, table="event_relations", keyvalues={"event_id": redacted_event_id}
Expand Down
8 changes: 0 additions & 8 deletions synapse/storage/databases/main/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,6 @@ def __init__(

self._msc3440_enabled = hs.config.experimental.msc3440_enabled

def _invalidate_relations_for_event(self, event_id: str) -> None:
"""Invalidate the relation caches for an event."""
self.get_relations_for_event.invalidate((event_id,))
self.get_aggregation_groups_for_event.invalidate((event_id,))
self.get_applicable_edit.invalidate((event_id,))
self.get_thread_summary.invalidate((event_id,))
self.get_thread_participated.invalidate((event_id,))

@cached(tree=True)
async def get_relations_for_event(
self,
Expand Down

0 comments on commit 6687bbd

Please sign in to comment.