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

active_record_extensions.rb#safe_send inefficiently searches for an attribute #1224

Merged

Conversation

christophermanning
Copy link
Contributor

Currently active_record_extensions#L20 uses self.attributes.find{ |k,v| k.to_s == value.to_s } to check the existence of an attribute, but this ends up unnecessarily calling the costly ActiveRecord AttributeMethods ClassMethods#generated_external_attribute_methods method.

It would be more efficient to look up the existence of an attribute at L20 with self.has_attribute?(value)

This prevents calling read_attribute once for every column in the table when searching for the attribute thereby reducing calls to expensive methods like generated_external_attribute_methods
mshibuya added a commit that referenced this pull request Jul 3, 2012
active_record_extensions.rb#safe_send inefficiently searches for an attribute
@mshibuya mshibuya merged commit 2207454 into railsadminteam:master Jul 3, 2012
@mshibuya
Copy link
Member

mshibuya commented Jul 3, 2012

Thanks for cleaning up!

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.

2 participants