mirror of
https://mau.dev/maunium/synapse.git
synced 2024-12-14 20:23:52 +01:00
Don't update event cache hit ratio from get_joined_users
Otherwise the hit ration of plain get_events gets completely skewed by calls to get_joined_users* functions.
This commit is contained in:
parent
dcabef952c
commit
ffad4fe35b
3 changed files with 21 additions and 5 deletions
|
@ -1343,11 +1343,20 @@ class EventsStore(SQLBaseStore):
|
||||||
def _invalidate_get_event_cache(self, event_id):
|
def _invalidate_get_event_cache(self, event_id):
|
||||||
self._get_event_cache.invalidate((event_id,))
|
self._get_event_cache.invalidate((event_id,))
|
||||||
|
|
||||||
def _get_events_from_cache(self, events, allow_rejected):
|
def _get_events_from_cache(self, events, allow_rejected, update_metrics=True):
|
||||||
|
"""
|
||||||
|
Args:
|
||||||
|
events (list(str)): list of event_ids to fetch
|
||||||
|
allow_rejected (bool): Whether to teturn events that were rejected
|
||||||
|
update_metrics (bool): Whether to update the cache hit ratio metrics
|
||||||
|
"""
|
||||||
event_map = {}
|
event_map = {}
|
||||||
|
|
||||||
for event_id in events:
|
for event_id in events:
|
||||||
ret = self._get_event_cache.get((event_id,), None)
|
ret = self._get_event_cache.get(
|
||||||
|
(event_id,), None,
|
||||||
|
update_metrics=update_metrics,
|
||||||
|
)
|
||||||
if not ret:
|
if not ret:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
|
@ -421,9 +421,13 @@ class RoomMemberStore(SQLBaseStore):
|
||||||
# We check if we have any of the member event ids in the event cache
|
# We check if we have any of the member event ids in the event cache
|
||||||
# before we ask the DB
|
# before we ask the DB
|
||||||
|
|
||||||
|
# We don't update the event cache hit ratio as it completely throws off
|
||||||
|
# the hit ratio counts. After all, we don't populate the cache if we
|
||||||
|
# miss it here
|
||||||
event_map = self._get_events_from_cache(
|
event_map = self._get_events_from_cache(
|
||||||
member_event_ids,
|
member_event_ids,
|
||||||
allow_rejected=False,
|
allow_rejected=False,
|
||||||
|
update_metrics=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
missing_member_event_ids = []
|
missing_member_event_ids = []
|
||||||
|
|
|
@ -96,7 +96,7 @@ class Cache(object):
|
||||||
"Cache objects can only be accessed from the main thread"
|
"Cache objects can only be accessed from the main thread"
|
||||||
)
|
)
|
||||||
|
|
||||||
def get(self, key, default=_CacheSentinel, callback=None):
|
def get(self, key, default=_CacheSentinel, callback=None, update_metrics=True):
|
||||||
"""Looks the key up in the caches.
|
"""Looks the key up in the caches.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
@ -104,6 +104,7 @@ class Cache(object):
|
||||||
default: What is returned if key is not in the caches. If not
|
default: What is returned if key is not in the caches. If not
|
||||||
specified then function throws KeyError instead
|
specified then function throws KeyError instead
|
||||||
callback(fn): Gets called when the entry in the cache is invalidated
|
callback(fn): Gets called when the entry in the cache is invalidated
|
||||||
|
update_metrics (bool): whether to update the cache hit rate metrics
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Either a Deferred or the raw result
|
Either a Deferred or the raw result
|
||||||
|
@ -113,7 +114,8 @@ class Cache(object):
|
||||||
if val is not _CacheSentinel:
|
if val is not _CacheSentinel:
|
||||||
if val.sequence == self.sequence:
|
if val.sequence == self.sequence:
|
||||||
val.callbacks.update(callbacks)
|
val.callbacks.update(callbacks)
|
||||||
self.metrics.inc_hits()
|
if update_metrics:
|
||||||
|
self.metrics.inc_hits()
|
||||||
return val.deferred
|
return val.deferred
|
||||||
|
|
||||||
val = self.cache.get(key, _CacheSentinel, callbacks=callbacks)
|
val = self.cache.get(key, _CacheSentinel, callbacks=callbacks)
|
||||||
|
@ -121,7 +123,8 @@ class Cache(object):
|
||||||
self.metrics.inc_hits()
|
self.metrics.inc_hits()
|
||||||
return val
|
return val
|
||||||
|
|
||||||
self.metrics.inc_misses()
|
if update_metrics:
|
||||||
|
self.metrics.inc_misses()
|
||||||
|
|
||||||
if default is _CacheSentinel:
|
if default is _CacheSentinel:
|
||||||
raise KeyError()
|
raise KeyError()
|
||||||
|
|
Loading…
Reference in a new issue