gitlab-org--gitlab-foss/app/models/concerns/throttled_touch.rb
Yorick Peterse 856447ccd3
Throttle the number of UPDATEs triggered by touch
This throttles the number of UPDATE queries that can be triggered by
calling "touch" on a Note, Issue, or MergeRequest. For Note objects we
also take care of updating the associated "noteable" relation in a
smarter way than Rails does by default.
2017-12-06 15:59:37 +01:00

10 lines
332 B
Ruby

# ThrottledTouch can be used to throttle the number of updates triggered by
# calling "touch" on an ActiveRecord model.
module ThrottledTouch
# The amount of time to wait before "touch" can update a record again.
TOUCH_INTERVAL = 1.minute
def touch(*args)
super if (Time.zone.now - updated_at) > TOUCH_INTERVAL
end
end