summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2018-05-29 16:12:26 +0000
committerYorick Peterse <yorickpeterse@gmail.com>2018-05-29 16:12:26 +0000
commita30e6b819bcf87c5297fe68bb54dd1751f7e0bfb (patch)
treea64cd31ab7b346da9668c87306bf1edf632be134
parente79f91df8c2a38238ebe5c76862d2f35307bb7f5 (diff)
parent61ea2f52bd32d5038b9eec1caf29a4d4531d03c4 (diff)
downloadgitlab-ce-a30e6b819bcf87c5297fe68bb54dd1751f7e0bfb.tar.gz
Merge branch 'ab-35364-throttle-updates-last-repository-at' into 'master'
Throttle updates to Project#last_repository_updated_at. Closes #35364 See merge request gitlab-org/gitlab-ce!19183
-rw-r--r--app/models/event.rb2
-rw-r--r--changelogs/unreleased/ab-35364-throttle-updates-last-repository-at.yml5
-rw-r--r--spec/models/event_spec.rb13
3 files changed, 20 insertions, 0 deletions
diff --git a/app/models/event.rb b/app/models/event.rb
index 741a84194e2..ac0b1c7b27c 100644
--- a/app/models/event.rb
+++ b/app/models/event.rb
@@ -40,6 +40,7 @@ class Event < ActiveRecord::Base
).freeze
RESET_PROJECT_ACTIVITY_INTERVAL = 1.hour
+ REPOSITORY_UPDATED_AT_INTERVAL = 5.minutes
delegate :name, :email, :public_email, :username, to: :author, prefix: true, allow_nil: true
delegate :title, to: :issue, prefix: true, allow_nil: true
@@ -391,6 +392,7 @@ class Event < ActiveRecord::Base
def set_last_repository_updated_at
Project.unscoped.where(id: project_id)
+ .where("last_repository_updated_at < ? OR last_repository_updated_at IS NULL", REPOSITORY_UPDATED_AT_INTERVAL.ago)
.update_all(last_repository_updated_at: created_at)
end
diff --git a/changelogs/unreleased/ab-35364-throttle-updates-last-repository-at.yml b/changelogs/unreleased/ab-35364-throttle-updates-last-repository-at.yml
new file mode 100644
index 00000000000..8e468233637
--- /dev/null
+++ b/changelogs/unreleased/ab-35364-throttle-updates-last-repository-at.yml
@@ -0,0 +1,5 @@
+---
+title: Throttle updates to Project#last_repository_updated_at.
+merge_request: 19183
+author:
+type: performance
diff --git a/spec/models/event_spec.rb b/spec/models/event_spec.rb
index 8ea92410022..c1eac4fa489 100644
--- a/spec/models/event_spec.rb
+++ b/spec/models/event_spec.rb
@@ -50,6 +50,19 @@ describe Event do
end
end
+ describe '#set_last_repository_updated_at' do
+ it 'only updates once every Event::REPOSITORY_UPDATED_AT_INTERVAL minutes' do
+ last_known_timestamp = (Event::REPOSITORY_UPDATED_AT_INTERVAL - 1.minute).ago
+ project.update(last_repository_updated_at: last_known_timestamp)
+ project.reload # a reload removes fractions of seconds
+
+ expect do
+ create_push_event(project, project.owner)
+ project.reload
+ end.not_to change { project.last_repository_updated_at }
+ end
+ end
+
describe 'after_create :track_user_interacted_projects' do
let(:event) { build(:push_event, project: project, author: project.owner) }