Commit f127edd0 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Merge branch '15094-throttle-update-of-last_activity_at' into 'master'

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

This implement [the solution](https://gitlab.com/gitlab-org/gitlab-ce/issues/15094#note_4769387) proposed by @jacobvosmaer.

See merge request !3848
parents 6ff740ff 533cd8c2
......@@ -6,6 +6,7 @@ v 8.8.0 (unreleased)
- Add 'l' shortcut to open Label dropdown on issuables and 'i' to create new issue on a project
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 @@ class Event < ActiveRecord::Base
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 @@ describe Event, models: true do
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 @@ describe Event, models: true do
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