ActiveRecord#touch should accept multiple attributes #14423

Merged
merged 1 commit into from Mar 20, 2014

Conversation

Projects
None yet
4 participants
@thejamespinto
Contributor

thejamespinto commented Mar 19, 2014

No description provided.

@thejamespinto

This comment has been minimized.

Show comment
Hide comment
@thejamespinto

thejamespinto Mar 19, 2014

Contributor

I wrote an extra test too

Contributor

thejamespinto commented Mar 19, 2014

I wrote an extra test too

@carlosantoniodasilva

This comment has been minimized.

Show comment
Hide comment
@carlosantoniodasilva

carlosantoniodasilva Mar 19, 2014

Member

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

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

@thejamespinto

This comment has been minimized.

Show comment
Hide comment
@thejamespinto

thejamespinto Mar 19, 2014

Contributor

this github page is a good example

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

Contributor

thejamespinto 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

raise ActiveRecordError, "cannot touch on a new record object" unless persisted?
attributes = timestamp_attributes_for_update_in_model
- attributes << name if name
+ attributes += names

This comment has been minimized.

@egilburg

egilburg Mar 19, 2014

Contributor

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

@egilburg

egilburg Mar 19, 2014

Contributor

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

This comment has been minimized.

@rafaelfranca

rafaelfranca Mar 19, 2014

Member

And we should do this only if we have any name

@rafaelfranca

rafaelfranca Mar 19, 2014

Member

And we should do this only if we have any name

This comment has been minimized.

@thejamespinto

thejamespinto Mar 19, 2014

Contributor

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

@thejamespinto

thejamespinto Mar 19, 2014

Contributor

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

raise ActiveRecordError, "cannot touch on a new record object" unless persisted?
attributes = timestamp_attributes_for_update_in_model
- attributes << name if name
+ attributes.concat(names)

This comment has been minimized.

@rafaelfranca

rafaelfranca Mar 19, 2014

Member

We need to check if names is not empty.

@rafaelfranca

rafaelfranca Mar 19, 2014

Member

We need to check if names is not empty.

This comment has been minimized.

@thejamespinto

thejamespinto Mar 19, 2014

Contributor

@rafaelfranca, I don't think it's necessary.
while using Array#concat, Array#empty? shows no difference performance penalties or benefits
Array#any? should be avoided in a Rails environment
image 2014-03-19 at 5 01 14 pm

@thejamespinto

thejamespinto Mar 19, 2014

Contributor

@rafaelfranca, I don't think it's necessary.
while using Array#concat, Array#empty? shows no difference performance penalties or benefits
Array#any? should be avoided in a Rails environment
image 2014-03-19 at 5 01 14 pm

@rafaelfranca

This comment has been minimized.

Show comment
Hide comment
@rafaelfranca

rafaelfranca Mar 19, 2014

Member

Could you add a CHANGELOG entry?

Member

rafaelfranca commented Mar 19, 2014

Could you add a CHANGELOG entry?

@egilburg

This comment has been minimized.

Show comment
Hide comment
@egilburg

egilburg Mar 19, 2014

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.

Contributor

egilburg commented Mar 19, 2014

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

thejamespinto added a commit to thejamespinto/rails that referenced this pull request Mar 19, 2014

@thejamespinto

This comment has been minimized.

Show comment
Hide comment
Contributor

thejamespinto commented Mar 19, 2014

@rafaelfranca

This comment has been minimized.

Show comment
Hide comment
@rafaelfranca

rafaelfranca Mar 19, 2014

Member

Could you squash your commits?

Member

rafaelfranca commented Mar 19, 2014

Could you squash your commits?

thejamespinto added a commit to thejamespinto/rails that referenced this pull request Mar 19, 2014

@thejamespinto

This comment has been minimized.

Show comment
Hide comment
@thejamespinto

thejamespinto Mar 19, 2014

Contributor

squashed it is

Contributor

thejamespinto commented Mar 19, 2014

squashed it is

thejamespinto added a commit to thejamespinto/rails that referenced this pull request Mar 20, 2014

activerecord/CHANGELOG.md
+ photo.sealed_at # was updated
+
+ *James Pinto*
+

This comment has been minimized.

@carlosantoniodasilva

carlosantoniodasilva Mar 20, 2014

Member

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

@carlosantoniodasilva

carlosantoniodasilva Mar 20, 2014

Member

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

@thejamespinto

This comment has been minimized.

Show comment
Hide comment
@thejamespinto

thejamespinto Mar 20, 2014

Contributor

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

Contributor

thejamespinto 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

Merge pull request #14423 from yakko/persistence-touches-many
ActiveRecord#touch should accept multiple attributes

Conflicts:
	activerecord/CHANGELOG.md

@carlosantoniodasilva carlosantoniodasilva merged commit c80ca4c into rails:master Mar 20, 2014

1 check passed

default The Travis CI build passed
Details

@nfm nfm referenced this pull request in godaddy/activerecord-delay_touching Apr 27, 2015

Closed

ActiveModel::MissingAttributeError: can't write unknown attribute `` #3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment