diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2016-09-16 16:05:12 +0200 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2016-09-19 16:48:58 +0200 |
commit | 028c086f902f56e26db6382caa6131404ce74dcd (patch) | |
tree | d1b84f3844f8b3b2bf1def1a15ff548e90d6c156 /app | |
parent | c20e4267e89c1fa84b3eeb9f63e17677388c25e3 (diff) | |
download | gitlab-ce-028c086f902f56e26db6382caa6131404ce74dcd.tar.gz |
Restrict last_activity_at updates to one per hour
The lock in turn is only obtained when actually needed, reducing some
load on Redis.
Fixes gitlab-org/gitlab-ce#22213
Diffstat (limited to 'app')
-rw-r--r-- | app/models/event.rb | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/app/models/event.rb b/app/models/event.rb index a0b7b0dc2b5..b6e8bef3f67 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -13,6 +13,8 @@ class Event < ActiveRecord::Base LEFT = 9 # User left project DESTROYED = 10 + RESET_PROJECT_ACTIVITY_INTERVAL = 1.hour + delegate :name, :email, to: :author, prefix: true, allow_nil: true delegate :title, to: :issue, prefix: true, allow_nil: true delegate :title, to: :merge_request, prefix: true, allow_nil: true @@ -324,8 +326,17 @@ class Event < ActiveRecord::Base end def reset_project_activity - if project && Gitlab::ExclusiveLease.new("project:update_last_activity_at:#{project.id}", timeout: 60).try_obtain - project.update_column(:last_activity_at, self.created_at) - end + return unless project + + # Don't even bother obtaining a lock if the last update happened less than + # 60 minutes ago. + return if project.last_activity_at > RESET_PROJECT_ACTIVITY_INTERVAL.ago + + return unless Gitlab::ExclusiveLease. + new("project:update_last_activity_at:#{project.id}", + timeout: RESET_PROJECT_ACTIVITY_INTERVAL.to_i). + try_obtain + + project.update_column(:last_activity_at, created_at) end end |