Skip to content

ActiveRecord#touch should accept multiple attributes#14423

Merged
carlosantoniodasilva merged 1 commit into
rails:masterfrom
ch1ago:persistence-touches-many
Mar 20, 2014
Merged

ActiveRecord#touch should accept multiple attributes#14423
carlosantoniodasilva merged 1 commit into
rails:masterfrom
ch1ago:persistence-touches-many

Conversation

@ch1ago
Copy link
Copy Markdown
Contributor

@ch1ago ch1ago commented Mar 19, 2014

No description provided.

@ch1ago
Copy link
Copy Markdown
Contributor Author

ch1ago commented Mar 19, 2014

I wrote an extra test too

@carlosantoniodasilva
Copy link
Copy Markdown
Member

Mind explaining a use case for many attributes being updated? Thanks.

@ch1ago
Copy link
Copy Markdown
Contributor Author

ch1ago commented Mar 19, 2014

this github page is a good example

When you press "close & comment",
I should update both "closed_at" and "last_commented_at" attributes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can use attributes.concat(names) to avoid extra object allocation.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And we should do this only if we have any name

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@egilburg I just bm'd it to 100_000_000 times,
the results show a 0.5 .. 1.3% performance improvement,
thanks for the tip 👍

@rafaelfranca
Copy link
Copy Markdown
Member

Could you add a CHANGELOG entry?

@egilburg
Copy link
Copy Markdown
Contributor

@yakko if we'd be getting into microoptimization, unless b.empty? would be slightly faster than if !b.empty? because ! is a method call in Ruby. But I don't think it'll be a meaningful difference.

@ch1ago
Copy link
Copy Markdown
Contributor Author

ch1ago commented Mar 19, 2014

@rafaelfranca done

@rafaelfranca
Copy link
Copy Markdown
Member

Could you squash your commits?

@ch1ago
Copy link
Copy Markdown
Contributor Author

ch1ago commented Mar 19, 2014

squashed it is

Comment thread activerecord/CHANGELOG.md Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last thing: this entry should be at the top. Thanks!

@ch1ago
Copy link
Copy Markdown
Contributor Author

ch1ago commented Mar 20, 2014

@rafaelfranca @carlosantoniodasilva the conditions were met and TravisCI has passed 👍

carlosantoniodasilva added a commit that referenced this pull request Mar 20, 2014
ActiveRecord#touch should accept multiple attributes

Conflicts:
	activerecord/CHANGELOG.md
@carlosantoniodasilva carlosantoniodasilva merged commit c80ca4c into rails:master Mar 20, 2014
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.

4 participants