Display unreferenced packages total size in package admin panel (#22498)

This commit is contained in:
Lunny Xiao 2023-01-18 23:52:04 +08:00 committed by GitHub
parent 7ddc11def7
commit f59ce77772
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

AI 샘플 코드 생성 중입니다

Loading...
6 changed files with 29 additions and 10 deletions

View File

@ -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")
}

View File

@ -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()).

View File

@ -2645,6 +2645,7 @@ repos.size = Size
packages.package_manage_panel = Package Management
packages.total_size = Total Size: %s
packages.unreferenced_size = Unreferenced Size: %s
packages.owner = Owner
packages.creator = Creator
packages.name = Name

View File

@ -51,12 +51,18 @@ func Packages(ctx *context.Context) {
return
}
totalBlobSize, err := packages_model.GetTotalBlobSize()
totalBlobSize, err := packages_model.GetTotalBlobSize(ctx)
if err != nil {
ctx.ServerError("GetTotalBlobSize", err)
return
}
totalUnreferencedBlobSize, err := packages_model.GetTotalUnreferencedBlobSize(ctx)
if err != nil {
ctx.ServerError("CalculateBlobSize", err)
return
}
ctx.Data["Title"] = ctx.Tr("packages.title")
ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminPackages"] = true
@ -65,8 +71,9 @@ func Packages(ctx *context.Context) {
ctx.Data["AvailableTypes"] = packages_model.TypeList
ctx.Data["SortType"] = sort
ctx.Data["PackageDescriptors"] = pds
ctx.Data["Total"] = total
ctx.Data["TotalBlobSize"] = totalBlobSize
ctx.Data["TotalCount"] = total
ctx.Data["TotalBlobSize"] = totalBlobSize - totalUnreferencedBlobSize
ctx.Data["TotalUnreferencedBlobSize"] = totalUnreferencedBlobSize
pager := context.NewPagination(int(total), setting.UI.PackagesPagingNum, page, 5)
pager.AddParamString("q", query)

View File

@ -361,11 +361,11 @@ func checkSizeQuotaExceeded(ctx context.Context, doer, owner *user_model.User, p
}
if setting.Packages.LimitTotalOwnerSize > -1 {
totalSize, err := packages_model.CalculateBlobSize(ctx, &packages_model.PackageFileSearchOptions{
totalSize, err := packages_model.CalculateFileSize(ctx, &packages_model.PackageFileSearchOptions{
OwnerID: owner.ID,
})
if err != nil {
log.Error("CalculateBlobSize failed: %v", err)
log.Error("CalculateFileSize failed: %v", err)
return err
}
if totalSize+uploadSize > setting.Packages.LimitTotalOwnerSize {

View File

@ -4,7 +4,9 @@
<div class="ui container">
{{template "base/alert" .}}
<h4 class="ui top attached header">
{{.locale.Tr "admin.packages.package_manage_panel"}} ({{.locale.Tr "admin.total" .Total}}, {{.locale.Tr "admin.packages.total_size" (FileSize .TotalBlobSize)}})
{{.locale.Tr "admin.packages.package_manage_panel"}} ({{.locale.Tr "admin.total" .TotalCount}},
{{.locale.Tr "admin.packages.total_size" (FileSize .TotalBlobSize)}},
{{.locale.Tr "admin.packages.unreferenced_size" (FileSize .TotalUnreferencedBlobSize)}})
</h4>
<div class="ui attached segment">
<form class="ui form ignore-dirty">