fix: quotas double counting repo size when calculating size:all (#9234)

Resolves forgejo/forgejo#7860

Reviewed-by: Gusted <postmaster@gusted.xyz>
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9234
Co-authored-by: Brook <brook@noreply.codeberg.org>
Co-committed-by: Brook <brook@noreply.codeberg.org>
This commit is contained in:
Brook 2025-09-11 16:30:04 +02:00 committed by Gusted
commit 4e1d4caf98
2 changed files with 35 additions and 4 deletions

View file

@ -25,7 +25,7 @@ type UsedSize struct {
}
func (u UsedSize) All() int64 {
return u.Repos.All() + u.Git.All(u.Repos) + u.Assets.All()
return u.Git.All(u.Repos) + u.Assets.All()
}
type UsedSizeRepos struct {

View file

@ -1,23 +1,54 @@
// Copyright 2025 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: GPL-3.0-or-later
package quota
package quota_test
import (
"testing"
quota_model "forgejo.org/models/quota"
"forgejo.org/models/unittest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestGetUsedForUser(t *testing.T) {
func TestQuotaUsedGetUsedForUser(t *testing.T) {
defer unittest.OverrideFixtures("models/fixtures/TestGetUsedForUser/")()
require.NoError(t, unittest.PrepareTestDatabase())
used, err := GetUsedForUser(t.Context(), 5)
used, err := quota_model.GetUsedForUser(t.Context(), 5)
require.NoError(t, err)
assert.EqualValues(t, 4096, used.Size.Assets.Artifacts)
}
func TestQuotaUsedTotals(t *testing.T) {
used := quota_model.Used{
Size: quota_model.UsedSize{
Repos: quota_model.UsedSizeRepos{
Public: 2,
Private: 3,
},
Git: quota_model.UsedSizeGit{
LFS: 7,
},
Assets: quota_model.UsedSizeAssets{
Attachments: quota_model.UsedSizeAssetsAttachments{
Issues: 11,
Releases: 13,
},
Artifacts: 17,
Packages: quota_model.UsedSizeAssetsPackages{
All: 19,
},
},
},
}
assert.EqualValues(t, 5, used.Size.Repos.All()) // repos public + repos private
assert.EqualValues(t, 12, used.Size.Git.All(used.Size.Repos)) // repos all + git lfs
assert.EqualValues(t, 24, used.Size.Assets.Attachments.All()) // issues + releases
assert.EqualValues(t, 60, used.Size.Assets.All()) // attachments all + artifacts + packages
assert.EqualValues(t, 72, used.Size.All()) // git all + assets all
}