Unverified Commit 533cd8c2 authored by Rémy Coutable's avatar Rémy Coutable
Browse files

Throttle the update of `project.last_activity_at` to 1 minute


Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 81cb636e
......@@ -4,6 +4,7 @@ v 8.8.0 (unreleased)
- Remove future dates from contribution calendar graph.
v 8.7.1 (unreleased)
- Throttle the update of `project.last_activity_at` to 1 minute. !3848
- Fix .gitlab-ci.yml parsing issue when hidde job is a template without script definition. !3849
- Fix license detection to detect all license files, not only known licenses. !3878
- Use the `can?` helper instead of `current_user.can?`. !3882
......
......@@ -345,7 +345,7 @@ def body?
end
def reset_project_activity
if project
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
end
......
......@@ -30,32 +30,29 @@
it { is_expected.to respond_to(:commits) }
end
describe 'Callbacks' do
describe 'after_create :reset_project_activity' do
let(:project) { create(:project) }
context "project's last activity was less than 5 minutes ago" do
it 'does not update project.last_activity_at if it has been touched less than 5 minutes ago' do
create_event(project, project.owner)
project.update_column(:last_activity_at, 5.minutes.ago)
project_last_activity_at = project.last_activity_at
create_event(project, project.owner)
expect(project.last_activity_at).to eq(project_last_activity_at)
end
end
end
end
describe "Push event" do
before do
project = create(:project)
@user = project.owner
data = {
before: Gitlab::Git::BLANK_SHA,
after: "0220c11b9a3e6c69dc8fd35321254ca9a7b98f7e",
ref: "refs/heads/master",
user_id: @user.id,
user_name: @user.name,
repository: {
name: project.name,
url: "localhost/rubinius",
description: "",
homepage: "localhost/rubinius",
private: true
}
}
@event = Event.create(
project: project,
action: Event::PUSHED,
data: data,
author_id: @user.id
)
@event = create_event(project, @user)
end
it { expect(@event.push?).to be_truthy }
......@@ -143,4 +140,28 @@
it { is_expected.to eq([event2]) }
end
end
def create_event(project, user, attrs = {})
data = {
before: Gitlab::Git::BLANK_SHA,
after: "0220c11b9a3e6c69dc8fd35321254ca9a7b98f7e",
ref: "refs/heads/master",
user_id: user.id,
user_name: user.name,
repository: {
name: project.name,
url: "localhost/rubinius",
description: "",
homepage: "localhost/rubinius",
private: true
}
}
Event.create({
project: project,
action: Event::PUSHED,
data: data,
author_id: user.id
}.merge(attrs))
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment