diff options
author | KN4CK3R <admin@oldschoolhack.me> | 2022-11-09 07:34:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-09 14:34:27 +0800 |
commit | 20674dd05da909b42cbdd07a6682fdf1d980f011 (patch) | |
tree | f51b4a6b907380d27381705e5b2e6a1187af167b /models/packages | |
parent | cb83288530b1860677b07d72bc4ce8349e3c0d67 (diff) | |
download | gitea-20674dd05da909b42cbdd07a6682fdf1d980f011.tar.gz gitea-20674dd05da909b42cbdd07a6682fdf1d980f011.zip |
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>
Diffstat (limited to 'models/packages')
-rw-r--r-- | models/packages/package_file.go | 10 | ||||
-rw-r--r-- | models/packages/package_version.go | 9 |
2 files changed, 19 insertions, 0 deletions
diff --git a/models/packages/package_file.go b/models/packages/package_file.go index 8f304ce8ac..9f6284af07 100644 --- a/models/packages/package_file.go +++ b/models/packages/package_file.go @@ -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") +} diff --git a/models/packages/package_version.go b/models/packages/package_version.go index 782261c575..48c6aa7d60 100644 --- a/models/packages/package_version.go +++ b/models/packages/package_version.go @@ -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)) +} |