parent
71dea693c6
commit
61ea2f52bd
3 changed files with 20 additions and 0 deletions
|
@ -40,6 +40,7 @@ class Event < ActiveRecord::Base
|
||||||
).freeze
|
).freeze
|
||||||
|
|
||||||
RESET_PROJECT_ACTIVITY_INTERVAL = 1.hour
|
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 :name, :email, :public_email, :username, to: :author, prefix: true, allow_nil: true
|
||||||
delegate :title, to: :issue, 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
|
def set_last_repository_updated_at
|
||||||
Project.unscoped.where(id: project_id)
|
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)
|
.update_all(last_repository_updated_at: created_at)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
title: Throttle updates to Project#last_repository_updated_at.
|
||||||
|
merge_request: 19183
|
||||||
|
author:
|
||||||
|
type: performance
|
|
@ -50,6 +50,19 @@ describe Event do
|
||||||
end
|
end
|
||||||
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
|
describe 'after_create :track_user_interacted_projects' do
|
||||||
let(:event) { build(:push_event, project: project, author: project.owner) }
|
let(:event) { build(:push_event, project: project, author: project.owner) }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue