-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Cache the value of changed_attributes
when calling changes_applied
#16646
Conversation
`changes_applied` calles `changes`, which will call `changed_attributes` multiple times in a loop. This method actually performs work now, so we should cache the results while looping over it when we know it cannot change.
Maybe |
@jeremy That would also require passing it to every method that |
end | ||
|
||
def changes | ||
cache_changed_attributes do |
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.
I'd rename it to caching_changed_attributes
because cache_
implies it will be persisted and not just set for duration of method execution.
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.
with_cached_changed_attributes
then? 😄
@sgrif How sweeping? Does it indicate an awkwardness in our implementation, in our state management, or ? Needing to set temporary instance state that implicitly affects other methods gets the job done, but by the same token it indicates that our design relies on implicitly consistent instance state rather than "snapshotting" the current changes and acting on them. |
Yes, and I'm planning on fixing that, but the refactoring I have in mind has more pre-requisites that I'm working on atm...
I agree, not happy with the design long-term. I'm actually not happy with the in-place implementation ATM, but I can't write the code I want to yet. Working on it. |
@jeremy Do I have additional action items that I need to do on this? |
@sgrif I was kinda hoping someone would pipe up with a better way 😁 Doesn't feel good to introduce a workaround like this and know it'll stick with us indefinitely. |
Except I've been actively working on this stuff for months, and said its on my radar? |
@sgrif True that! ❤️ |
Cache the value of `changed_attributes` when calling `changes_applied`
changes_applied
calleschanges
, which will callchanged_attributes
multiple times in a loop. This method actually performs work now, so we
should cache the results while looping over it when we know it cannot
change.