summaryrefslogtreecommitdiff
path: root/app/models/concerns/throttled_touch.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/concerns/throttled_touch.rb')
-rw-r--r--app/models/concerns/throttled_touch.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/app/models/concerns/throttled_touch.rb b/app/models/concerns/throttled_touch.rb
new file mode 100644
index 00000000000..ad0ff0f20d4
--- /dev/null
+++ b/app/models/concerns/throttled_touch.rb
@@ -0,0 +1,10 @@
+# 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