Bust caches in User::active_profile and User::pending_profile#9760
Merged
Bust caches in User::active_profile and User::pending_profile#9760
Conversation
If the `active` state of a Profile does not match what's expected when calling User::active_profile or User::pending_profile, clear the cached value. This is mostly a convenience for tests. [skip changelog]
Since they were referencing a profile that's not actually pending anymore.
matthinz
commented
Dec 14, 2023
Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>
jmhooper
approved these changes
Dec 14, 2023
aduth
reviewed
Dec 14, 2023
Contributor
|
Typically I might imagine the invalidation would happen at the same time as the state transition, but I suppose that's a little tricky here with how this method is defined in a separate class. |
Not actually required to achieve the same effect.
Since these calls are preceded by .reload (which busts the cache), these are no longer the _exact same_ objects, even though they refer to the same records
e292f4e to
0909766
Compare
Contributor
Author
|
Sorry for the churn here, all. I got confused and didn't realize that we aren't currently caching
|
jmhooper
approved these changes
Dec 15, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🛠 Summary of changes
User::active_profileandUser::pending_profileboth cache their results in instance variables. This is fine, but sometimes, especially in tests, those caches get stale, and there's not a straightforward way to bust them without creating a new User instance (for example,User::reloaddoes not clear those cached instance variables).This PR updates
active_profileandpending_profileto check whether the cached Profile they're about to return are still active or pending, and busts the cache if something has changed.