New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix call to inefficient delete_matched
cache method in domain blocks
#28374
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #28374 +/- ##
==========================================
+ Coverage 83.49% 83.70% +0.21%
==========================================
Files 1038 1038
Lines 28241 28281 +40
Branches 4556 4576 +20
==========================================
+ Hits 23580 23673 +93
+ Misses 3533 3479 -54
- Partials 1128 1129 +1 ☔ View full report in Codecov by Sentry. |
Looks good overall, left some misc style comments ... is there any spec coverage we could around the "reduce redis round trips" portion of this? ... set up some scenario which would have been 2 or 3 round trips before but is now one in the |
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.
Looks good to me, but I do not know this area very well.
Are there tests covering this?
There are tests covering the functionality, but not the performance. |
The tests are actually only testing the cold cache path, and my understanding of |
This changes the cache the relationship cache keys
583439a
to
8f37f0b
Compare
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.
Looks good, but if this caused problems after deploying the previous version, then we are probably missing a test?
Yeah. Just pushed some changes to the specs to add tests for a warm cache. |
Related commit: 7d9b209 Fix call to inefficient `delete_matched` cache method in domain blocks (mastodon#28374)
Related commit: 7d9b209 Fix call to inefficient `delete_matched` cache method in domain blocks (mastodon#28374)
All cached relationships for an account were being cleared in bulk using
Rails.cache.delete_matched
when blocking an account. However,delete_matched
iters through all cache keys and does not have any optimization for matching by prefix, which has a very significant performance impact.The information of whether an account is domain-blocked by the current user has been moved outside of the relationships cache and is instead cached in a per-domain cache. In the worst case, this would double the number of cache keys used for a relationship cache, but it should slightly reduce the amount of data duplication throughout the cache.
The code has also been changed to use
read_multi
to request most cache keys at once and thus reduce the number of Redis queries per access to relationship caches. This also changes the relationship cache keys fromrelationship:<account>:<second_account>
torelationship/<account>/<second_account>
as it is how Rails internally splits cache key components.