Skip to content

Update timestamp in AR#increment! - #21979

Closed
akihiro17 wants to merge 1 commit into
rails:masterfrom
akihiro17:increment-updates-timestamp
Closed

akihiro17 wants to merge 1 commit into
rails:masterfrom
akihiro17:increment-updates-timestamp

Conversation

@akihiro17

Copy link
Copy Markdown
Contributor

Now, AR#increment! is concurrent safe(#11410). However, this commit breaks backward compatability because .update_counters doesn't update timestamp.

Here is a reproduction script for this issue.
https://gist.github.com/akihiro17/aa08276f5d0f72d9869b

In this commit, .update_counters updates timestamp if both touch and record_time_stamp are true.

Now, AR#increment! is concurrent safe(rails#11410). However, this commit breaks backward compatability because `.update_counters` doesn't update timestamp.

Here is a reproduction script for this issue.
https://gist.github.com/akihiro17/aa08276f5d0f72d9869b

In this commit, `.update_counters` updates timestamp if both `touch` and `record_time_stamp` are true.
@rails-bot

Copy link
Copy Markdown

r? @kaspth

(@rails-bot has picked a reviewer for you, use r? to override)

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.

are these intended to be user-overridable?

if yes, should you use these methods rather than constants in https://github.com/rails/rails/pull/21979/files#diff-ec4e6359a60e5d11bbc4bd0912265c27R87 ? if not, why not just remove the methods and use the constants directly?

@bogdan

bogdan commented Oct 18, 2015

Copy link
Copy Markdown
Contributor

r? @jeremy

It is very strange that #increment! uses accessor method but #increment doesn't. This is counterintuitive behavior. I would prefer both or none of them to use accessor.

Good catch with touch. But it is still questionable: perform touch but do not perform a validation. I am also not sure touch should be permanent. In my use cases I would prefer no touch. Not sure we can change the behavior. @jeremy what do you think?

@kaspth

kaspth commented Jan 8, 2017

Copy link
Copy Markdown
Contributor

Timestamp touching has been added to update_counters and friends:

# Post.update_counters [10, 15], comment_count: 1, touch: true

It's on track for 5.1. Thanks! 😉

@kaspth kaspth closed this Jan 8, 2017
@eugeneius

Copy link
Copy Markdown
Member

It's still not possible to touch the record when calling increment! or decrement! though.

With the changes from #26995, the implementation should be pretty straightforward - increment! just needs to pass touch: to update_counters.

@kaspth

kaspth commented Jan 9, 2017

Copy link
Copy Markdown
Contributor

PR welcome 🤘

@eugeneius

Copy link
Copy Markdown
Member

I'll give @akihiro17 a chance to pick this back up if they want to first.

@akihiro17

Copy link
Copy Markdown
Contributor Author

@kaspth @eugeneius

I created #27660.

Thanks.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants