Commit decf6fb0 authored by Corinna Wiesner's avatar Corinna Wiesner Committed by Tyler Amos

Avoid using the current's project excess twice

The calculation for the exceeded size for a project used the project's
excess size twice as it was also included in the total repository size
excess. This is corrected by calculating the project's excess size and
substracting it from the total repository size.
parent 0177b2c0
...@@ -19,7 +19,7 @@ module EE ...@@ -19,7 +19,7 @@ module EE
def exceeded_size(change_size = 0) def exceeded_size(change_size = 0)
exceeded_size = super exceeded_size = super
exceeded_size -= remaining_additional_purchased_storage if additional_repo_storage_available? exceeded_size -= remaining_additional_purchased_storage if additional_repo_storage_available?
exceeded_size [exceeded_size, 0].max
end end
private private
...@@ -38,8 +38,16 @@ module EE ...@@ -38,8 +38,16 @@ module EE
namespace&.additional_purchased_storage_size&.megabytes.to_i namespace&.additional_purchased_storage_size&.megabytes.to_i
end end
def current_project_excess
[current_size - limit, 0].max
end
def total_excess_without_current_project
total_repository_size_excess - current_project_excess
end
def remaining_additional_purchased_storage def remaining_additional_purchased_storage
additional_purchased_storage - total_repository_size_excess additional_purchased_storage - total_excess_without_current_project
end end
end end
end end
......
...@@ -136,26 +136,37 @@ RSpec.describe Gitlab::RepositorySizeChecker do ...@@ -136,26 +136,37 @@ RSpec.describe Gitlab::RepositorySizeChecker do
stub_feature_flags(namespace_storage_limit: false) stub_feature_flags(namespace_storage_limit: false)
end end
context 'when current size + total repository size excess are below or equal to the limit + additional purchased storage' do context 'with additional purchased storage' do
let(:current_size) { 50 }
let(:total_repository_size_excess) { 10 } let(:total_repository_size_excess) { 10 }
let(:additional_purchased_storage) { 10 } let(:additional_purchased_storage) { 10 }
context 'when current size + total repository size excess are below or equal to the project\'s limit (no need for additional purchase storage)' do
let(:current_size) { 50 }
it 'returns zero' do it 'returns zero' do
expect(subject.exceeded_size).to eq(0) expect(subject.exceeded_size).to eq(0)
end end
end end
context 'when current size + total repository size excess are over the limit + additional purchased storage' do context 'when there is remaining storage (current size + excess for other projects need to use additional purchased storage but not all of it)' do
let(:current_size) { 51 } let(:current_size) { 51 }
let(:total_repository_size_excess) { 10 }
let(:additional_purchased_storage) { 10 } it 'returns 0' do
expect(subject.exceeded_size).to eq(0)
end
end
context 'when there storage is exceeded (current size + excess for other projects exceed additional purchased storage' do
let(:total_repository_size_excess) { 15 }
let(:current_size) { 61 }
it 'returns 1' do it 'returns 1' do
expect(subject.exceeded_size).to eq(1.megabytes) expect(subject.exceeded_size).to eq(5.megabytes)
end
end end
end end
context 'without additional purchased storage' do
context 'when change size will be over the limit' do context 'when change size will be over the limit' do
let(:current_size) { 50 } let(:current_size) { 50 }
...@@ -172,6 +183,7 @@ RSpec.describe Gitlab::RepositorySizeChecker do ...@@ -172,6 +183,7 @@ RSpec.describe Gitlab::RepositorySizeChecker do
end end
end end
end end
end
context 'with feature flag :additional_repo_storage_by_namespace disabled' do context 'with feature flag :additional_repo_storage_by_namespace disabled' do
before do before 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