diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2023-01-18 23:52:04 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-18 09:52:04 -0600 |
commit | f59ce777728cf84ccdf711491772104a0fc0dd6e (patch) | |
tree | b77b85f70a9b53decf87db3b7414736fd49b0234 /models/packages | |
parent | 7ddc11def7e524df194cd67a93cf83cf733b1b79 (diff) | |
download | gitea-f59ce777728cf84ccdf711491772104a0fc0dd6e.tar.gz gitea-f59ce777728cf84ccdf711491772104a0fc0dd6e.zip |
Display unreferenced packages total size in package admin panel (#22498)
Diffstat (limited to 'models/packages')
-rw-r--r-- | models/packages/package_blob.go | 13 | ||||
-rw-r--r-- | models/packages/package_file.go | 4 |
2 files changed, 13 insertions, 4 deletions
diff --git a/models/packages/package_blob.go b/models/packages/package_blob.go index 3b4a1ecf18..a55109af96 100644 --- a/models/packages/package_blob.go +++ b/models/packages/package_blob.go @@ -85,7 +85,16 @@ func DeleteBlobByID(ctx context.Context, blobID int64) error { } // GetTotalBlobSize returns the total blobs size in bytes -func GetTotalBlobSize() (int64, error) { - return db.GetEngine(db.DefaultContext). +func GetTotalBlobSize(ctx context.Context) (int64, error) { + return db.GetEngine(ctx). + SumInt(&PackageBlob{}, "size") +} + +// GetTotalUnreferencedBlobSize returns the total size of all unreferenced blobs in bytes +func GetTotalUnreferencedBlobSize(ctx context.Context) (int64, error) { + return db.GetEngine(ctx). + Table("package_blob"). + Join("LEFT", "package_file", "package_file.blob_id = package_blob.id"). + Where("package_file.id IS NULL"). SumInt(&PackageBlob{}, "size") } diff --git a/models/packages/package_file.go b/models/packages/package_file.go index 7f794836dc..97e7a0d407 100644 --- a/models/packages/package_file.go +++ b/models/packages/package_file.go @@ -199,9 +199,9 @@ func SearchFiles(ctx context.Context, opts *PackageFileSearchOptions) ([]*Packag return pfs, count, err } -// CalculateBlobSize sums up all blob sizes matching the search options. +// CalculateFileSize sums up all blob sizes matching the search options. // It does NOT respect the deduplication of blobs. -func CalculateBlobSize(ctx context.Context, opts *PackageFileSearchOptions) (int64, error) { +func CalculateFileSize(ctx context.Context, opts *PackageFileSearchOptions) (int64, error) { return db.GetEngine(ctx). Table("package_file"). Where(opts.toConds()). |