Commit d48ee860 authored by Stan Hu's avatar Stan Hu

Make Housekeeping button do a full garbage collection

Previously the Housekeeping button and API would use the counter of last
pushes to determine whether to do a full garbage collection, or whether
to do one of the less comprehensive tasks: a full repack, incremental
pack, or ref pack. This was confusing behavior, since a project owner
might have to click the button dozens of times before a full GC would be
initiated.

This commit forces a full GC each time this is initiated. Note that the
`ExclusiveLease` in `HousekeepingService` prevents users from clicking
on the button more than once a day.

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/63349
parent 38d46edb
...@@ -182,7 +182,7 @@ class ProjectsController < Projects::ApplicationController ...@@ -182,7 +182,7 @@ class ProjectsController < Projects::ApplicationController
end end
def housekeeping def housekeeping
::Projects::HousekeepingService.new(@project).execute ::Projects::HousekeepingService.new(@project, :gc).execute
redirect_to( redirect_to(
project_path(@project), project_path(@project),
......
---
title: Make Housekeeping button do a full garbage collection
merge_request: 30289
author:
type: fixed
...@@ -474,7 +474,7 @@ module API ...@@ -474,7 +474,7 @@ module API
authorize_admin_project authorize_admin_project
begin begin
::Projects::HousekeepingService.new(user_project).execute ::Projects::HousekeepingService.new(user_project, :gc).execute
rescue ::Projects::HousekeepingService::LeaseTaken => error rescue ::Projects::HousekeepingService::LeaseTaken => error
conflict!(error.message) conflict!(error.message)
end end
......
...@@ -318,6 +318,53 @@ describe ProjectsController do ...@@ -318,6 +318,53 @@ describe ProjectsController do
end end
end end
describe '#housekeeping' do
let(:group) { create(:group) }
let(:project) { create(:project, group: group) }
let(:housekeeping) { Projects::HousekeepingService.new(project) }
context 'when authenticated as owner' do
before do
group.add_owner(user)
sign_in(user)
allow(Projects::HousekeepingService).to receive(:new).with(project, :gc).and_return(housekeeping)
end
it 'forces a full garbage collection' do
expect(housekeeping).to receive(:execute).once
post :housekeeping,
params: {
namespace_id: project.namespace.path,
id: project.path
}
expect(response).to have_gitlab_http_status(302)
end
end
context 'when authenticated as developer' do
let(:developer) { create(:user) }
before do
group.add_developer(developer)
end
it 'does not execute housekeeping' do
expect(housekeeping).not_to receive(:execute)
post :housekeeping,
params: {
namespace_id: project.namespace.path,
id: project.path
}
expect(response).to have_gitlab_http_status(302)
end
end
end
describe "#update" do describe "#update" do
render_views render_views
......
...@@ -2428,7 +2428,7 @@ describe API::Projects do ...@@ -2428,7 +2428,7 @@ describe API::Projects do
let(:housekeeping) { Projects::HousekeepingService.new(project) } let(:housekeeping) { Projects::HousekeepingService.new(project) }
before do before do
allow(Projects::HousekeepingService).to receive(:new).with(project).and_return(housekeeping) allow(Projects::HousekeepingService).to receive(:new).with(project, :gc).and_return(housekeeping)
end end
context 'when authenticated as owner' do context 'when authenticated as owner' do
......
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