-
Notifications
You must be signed in to change notification settings - Fork 85
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
Disable cache outside transactions #2067
Conversation
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.
So is it better to not have a query cache in prePeek or to start a transaction in prePeek so we can take advantage of the cache?
Why is this an issue? |
I assume it is because the cache needs to be invalidated when there's a write |
Yeah but I was trying to understand where/how we do that and why it matters whether we're in a transaction. Looking at the code, I still don't understand how the issue would happen. We clear
What am I missing? As an aside, I checked logs to see how frequently we use this cache, and it looks like we use it a ton, so this optimization is probably a very good one |
This happens when two different commands run simultaneously. The query cache is per DB handle. So if you run a query in The cache is command 1 is not cleared when command 2 performs a write. This never mattered inside a transaction, but does without transactions. This doesn't only affect a single command, either. If If another command is given the same DB handle, and attempts the same query, it will get the cached result from the previous command that ran it. It affects |
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.
Confirmed that this is fixing the cache issue I found here: https://expensify.slack.com/archives/C05CBC62HGW/p1738208970608929?thread_ts=1738090282.125069&cid=C05CBC62HGW
I don't think this counts as an "optimization", it is fixing a bug where we read from the cache stale data. I understand that It can potentially make things slower, not faster because you are no longer caching queries in prePeek/postProcess. |
Details
This disables caching query results when we're not in a transaction (particularly, in prePeek). Because there is no transaction, there's no way to know if the database has changed after any of these queries. This was discovered in the HC-Tree version of
JoinAccessiblePolicyTest
but it could happen in any command with prePeek.Fixed Issues
https://github.com/Expensify/Expensify/issues/337537
Tests
Internal Testing Reminder: when changing bedrock, please compile auth against your new changes