mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-18 01:10:27 -04:00
Check the stream position before checking if the cache is empty. (#14639)
An empty cache does not mean the entity has no changed, if it is earlier than the earliest known stream position return that the entity *has* changed since the cache cannot accurately answer that query.
This commit is contained in:
parent
f3ad68c343
commit
da77720752
3 changed files with 10 additions and 7 deletions
|
@ -213,16 +213,17 @@ class StreamChangeCache:
|
|||
"""
|
||||
assert isinstance(stream_pos, int)
|
||||
|
||||
if not self._cache:
|
||||
# If the cache is empty, nothing can have changed.
|
||||
return False
|
||||
|
||||
# _cache is not valid at or before the earliest known stream position, so
|
||||
# return that an entity has changed.
|
||||
if stream_pos <= self._earliest_known_stream_pos:
|
||||
self.metrics.inc_misses()
|
||||
return True
|
||||
|
||||
# If the cache is empty, nothing can have changed.
|
||||
if not self._cache:
|
||||
self.metrics.inc_misses()
|
||||
return False
|
||||
|
||||
self.metrics.inc_hits()
|
||||
return stream_pos < self._cache.peekitem()[0]
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue