Skip to content
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

Merged
merged 1 commit into from
Aug 26, 2014

Conversation

sgrif
Copy link
Contributor

@sgrif sgrif commented Aug 22, 2014

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.

`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.
@jeremy
Copy link
Member

jeremy commented Aug 22, 2014

Maybe #changes should accept a hash of changed attrs, instead, that defaults to changed_attributes? The construction here is admirable but surprising & brittle, too.

@sgrif
Copy link
Contributor Author

sgrif commented Aug 22, 2014

@jeremy That would also require passing it to every method that changes calls, which is nearly every method in dirty checking. I'm not opposed to passing it in optionally, but it's fairly sweeping.

end

def changes
cache_changed_attributes do
Copy link
Contributor

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.

Copy link
Member

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? 😄

@jeremy
Copy link
Member

jeremy commented Aug 23, 2014

@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.

@sgrif
Copy link
Contributor Author

sgrif commented Aug 23, 2014

Does it indicate an awkwardness in our implementation, in our state management, or ?

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...

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.

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.

@sgrif
Copy link
Contributor Author

sgrif commented Aug 25, 2014

@jeremy Do I have additional action items that I need to do on this?

@jeremy
Copy link
Member

jeremy commented Aug 26, 2014

@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.

@sgrif
Copy link
Contributor Author

sgrif commented Aug 26, 2014

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?

@jeremy
Copy link
Member

jeremy commented Aug 26, 2014

@sgrif True that! ❤️

jeremy added a commit that referenced this pull request Aug 26, 2014
Cache the value of `changed_attributes` when calling `changes_applied`
@jeremy jeremy merged commit 99a5333 into rails:master Aug 26, 2014
@sgrif sgrif deleted the sg-perf-regression branch March 14, 2018 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants