-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Check the stream position before checking if the cache is empty. #14639
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix a long-standing bug where the user directory and room/user stats might be out of sync. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -213,16 +213,17 @@ def has_any_entity_changed(self, stream_pos: int) -> bool: | |
""" | ||
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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should add a comment here that the ordering is important. Something like:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @clokep Thoughts? Picking this up? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is necessary -- the updated comments are clear and the tests assert this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @clokep I don't pick any of this information up from the comments. Only from your PR description. It's great that we have tests for this though. |
||
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] | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that
has_any_entity_changed
only has a single caller:get_partial_current_state_deltas
, which is called fromget_current_state_deltas
which affects presence, stats, and the user directory.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Searching the matrix.org database to see if there are descrepencies that could be due to this (or #14435 or #14592) shows that there are rooms where the room stats do not match current state events, this makes me think the user directory table might also be out of date? (I'll file a separate issue about this, I think.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #14643.