Add index to cache invalidations (#12747)

For workers that rarely write to the cache the `get_all_updated_caches`
query can become expensive if the worker falls behind when reading the
cache.
This commit is contained in:
Erik Johnston 2022-05-17 10:34:59 +01:00 committed by GitHub
parent fcf951d5dc
commit 32ef24fbd7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 0 deletions

View file

@ -57,6 +57,14 @@ class CacheInvalidationWorkerStore(SQLBaseStore):
self._instance_name = hs.get_instance_name()
self.db_pool.updates.register_background_index_update(
update_name="cache_invalidation_index_by_instance",
index_name="cache_invalidation_stream_by_instance_instance_index",
table="cache_invalidation_stream_by_instance",
columns=("instance_name", "stream_id"),
psql_only=True, # The table is only on postgres DBs.
)
async def get_all_updated_caches(
self, instance_name: str, last_id: int, current_id: int, limit: int
) -> Tuple[List[Tuple[int, tuple]], int, bool]: