summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2017-05-09 14:46:50 +0000
committerDouwe Maan <douwe@gitlab.com>2017-05-09 14:46:50 +0000
commitdccf5f19f911eaf8d32e37e9f369a46d9e7ec9bd (patch)
treebf85d85d79b885b90f20ed587fc7ea77387095c3 /app
parent2aa084a484784bc72e85dbaa82189a66a913e352 (diff)
parent3531ea096f730b8533df259ac2f6cbed738965ed (diff)
downloadgitlab-ce-dccf5f19f911eaf8d32e37e9f369a46d9e7ec9bd.tar.gz
Merge branch 'tc-cache-trackable-attributes' into 'master'
Limit User's trackable attributes to update at most once/hour Closes #22068 See merge request !11053
Diffstat (limited to 'app')
-rw-r--r--app/models/user.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/app/models/user.rb b/app/models/user.rb
index 4e5f94683b8..77b2b12ee0b 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -40,6 +40,17 @@ class User < ActiveRecord::Base
devise :lockable, :recoverable, :rememberable, :trackable,
:validatable, :omniauthable, :confirmable, :registerable
+ # Override Devise::Models::Trackable#update_tracked_fields!
+ # to limit database writes to at most once every hour
+ def update_tracked_fields!(request)
+ update_tracked_fields(request)
+
+ lease = Gitlab::ExclusiveLease.new("user_update_tracked_fields:#{id}", timeout: 1.hour.to_i)
+ return unless lease.try_obtain
+
+ save(validate: false)
+ end
+
attr_accessor :force_random_password
# Virtual attribute for authenticating by either username or email