Fix container download counter (#19287)

* Increment counter on manifest download.

* Refactor GetPackageFileStream method.
pull/19281/head^2
KN4CK3R 3 years ago committed by GitHub
parent 242d71035a
commit 08d199245a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      routers/api/packages/container/container.go
  2. 8
      routers/api/packages/nuget/nuget.go
  3. 1
      routers/web/user/package.go
  4. 8
      services/packages/packages.go

@ -367,7 +367,7 @@ func GetBlob(ctx *context.Context) {
return
}
s, err := packages_module.NewContentStore().Get(packages_module.BlobHash256Key(blob.Blob.HashSHA256))
s, _, err := packages_service.GetPackageFileStream(ctx, blob.File)
if err != nil {
apiError(ctx, http.StatusInternalServerError, err)
return
@ -506,7 +506,7 @@ func GetManifest(ctx *context.Context) {
return
}
s, err := packages_module.NewContentStore().Get(packages_module.BlobHash256Key(manifest.Blob.HashSHA256))
s, _, err := packages_service.GetPackageFileStream(ctx, manifest.File)
if err != nil {
apiError(ctx, http.StatusInternalServerError, err)
return

@ -376,13 +376,7 @@ func DownloadSymbolFile(ctx *context.Context) {
return
}
pv, err := packages_model.GetVersionByID(ctx, pfs[0].VersionID)
if err != nil {
apiError(ctx, http.StatusInternalServerError, err)
return
}
s, _, err := packages_service.GetPackageFileStream(ctx, pv, pfs[0])
s, _, err := packages_service.GetPackageFileStream(ctx, pfs[0])
if err != nil {
if err == packages_model.ErrPackageNotExist || err == packages_model.ErrPackageFileNotExist {
apiError(ctx, http.StatusNotFound, err)

@ -331,7 +331,6 @@ func DownloadPackageFile(ctx *context.Context) {
s, _, err := packages_service.GetPackageFileStream(
ctx,
ctx.Package.Descriptor.Version,
pf,
)
if err != nil {

@ -426,7 +426,7 @@ func GetFileStreamByPackageVersionAndFileID(ctx context.Context, owner *user_mod
return nil, nil, err
}
return GetPackageFileStream(ctx, pv, pf)
return GetPackageFileStream(ctx, pf)
}
// GetFileStreamByPackageVersion returns the content of the specific package file
@ -436,11 +436,11 @@ func GetFileStreamByPackageVersion(ctx context.Context, pv *packages_model.Packa
return nil, nil, err
}
return GetPackageFileStream(ctx, pv, pf)
return GetPackageFileStream(ctx, pf)
}
// GetPackageFileStream returns the content of the specific package file
func GetPackageFileStream(ctx context.Context, pv *packages_model.PackageVersion, pf *packages_model.PackageFile) (io.ReadCloser, *packages_model.PackageFile, error) {
func GetPackageFileStream(ctx context.Context, pf *packages_model.PackageFile) (io.ReadCloser, *packages_model.PackageFile, error) {
pb, err := packages_model.GetBlobByID(ctx, pf.BlobID)
if err != nil {
return nil, nil, err
@ -449,7 +449,7 @@ func GetPackageFileStream(ctx context.Context, pv *packages_model.PackageVersion
s, err := packages_module.NewContentStore().Get(packages_module.BlobHash256Key(pb.HashSHA256))
if err == nil {
if pf.IsLead {
if err := packages_model.IncrementDownloadCounter(ctx, pv.ID); err != nil {
if err := packages_model.IncrementDownloadCounter(ctx, pf.VersionID); err != nil {
log.Error("Error incrementing download counter: %v", err)
}
}

Loading…
Cancel
Save