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

Commit

Permalink
Cache is_partial_state_room (#13693)
Browse files Browse the repository at this point in the history
Fixes #13613.
  • Loading branch information
erikjohnston authored Sep 1, 2022
1 parent c913e44 commit 9d2823a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog.d/13693.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add cache to `is_partial_state_room`.
11 changes: 7 additions & 4 deletions synapse/storage/databases/main/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -1185,8 +1185,9 @@ async def clear_partial_state_room(self, room_id: str) -> bool:
)
return False

@staticmethod
def _clear_partial_state_room_txn(txn: LoggingTransaction, room_id: str) -> None:
def _clear_partial_state_room_txn(
self, txn: LoggingTransaction, room_id: str
) -> None:
DatabasePool.simple_delete_txn(
txn,
table="partial_state_rooms_servers",
Expand All @@ -1197,7 +1198,9 @@ def _clear_partial_state_room_txn(txn: LoggingTransaction, room_id: str) -> None
table="partial_state_rooms",
keyvalues={"room_id": room_id},
)
self._invalidate_cache_and_stream(txn, self.is_partial_state_room, (room_id,))

@cached()
async def is_partial_state_room(self, room_id: str) -> bool:
"""Checks if this room has partial state.
Expand Down Expand Up @@ -1771,9 +1774,8 @@ async def store_partial_state_room(
servers,
)

@staticmethod
def _store_partial_state_room_txn(
txn: LoggingTransaction, room_id: str, servers: Collection[str]
self, txn: LoggingTransaction, room_id: str, servers: Collection[str]
) -> None:
DatabasePool.simple_insert_txn(
txn,
Expand All @@ -1788,6 +1790,7 @@ def _store_partial_state_room_txn(
keys=("room_id", "server_name"),
values=((room_id, s) for s in servers),
)
self._invalidate_cache_and_stream(txn, self.is_partial_state_room, (room_id,))

async def maybe_store_room_on_outlier_membership(
self, room_id: str, room_version: RoomVersion
Expand Down

0 comments on commit 9d2823a

Please sign in to comment.