mirror of
https://codeberg.org/forgejo/forgejo
synced 2024-11-22 01:44:24 +01:00
Display unreferenced packages total size in package admin panel (#22498)
This commit is contained in:
parent
7ddc11def7
commit
f59ce77772
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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()).
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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">
|
||||
|
|
Loading…
Reference in a new issue