mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	Add package registry quota limits (#21584)
Related #20471 This PR adds global quota limits for the package registry. Settings for individual users/orgs can be added in a seperate PR using the settings table. Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
		@@ -199,3 +199,13 @@ func SearchFiles(ctx context.Context, opts *PackageFileSearchOptions) ([]*Packag
 | 
			
		||||
	count, err := sess.FindAndCount(&pfs)
 | 
			
		||||
	return pfs, count, err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// CalculateBlobSize 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) {
 | 
			
		||||
	return db.GetEngine(ctx).
 | 
			
		||||
		Table("package_file").
 | 
			
		||||
		Where(opts.toConds()).
 | 
			
		||||
		Join("INNER", "package_blob", "package_blob.id = package_file.blob_id").
 | 
			
		||||
		SumInt(new(PackageBlob), "size")
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -319,3 +319,12 @@ func SearchLatestVersions(ctx context.Context, opts *PackageSearchOptions) ([]*P
 | 
			
		||||
	count, err := sess.FindAndCount(&pvs)
 | 
			
		||||
	return pvs, count, err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// CountVersions counts all versions of packages matching the search options
 | 
			
		||||
func CountVersions(ctx context.Context, opts *PackageSearchOptions) (int64, error) {
 | 
			
		||||
	return db.GetEngine(ctx).
 | 
			
		||||
		Where(opts.toConds()).
 | 
			
		||||
		Table("package_version").
 | 
			
		||||
		Join("INNER", "package", "package.id = package_version.package_id").
 | 
			
		||||
		Count(new(PackageVersion))
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user