Fix handling of plenty Nuget package versions (#26075)
Fixes #25953 - Do not load full version information (v3) - Add pagination support (v2)
This commit is contained in:
parent
6ce89883eb
commit
2d7fe4cc1e
5 changed files with 138 additions and 38 deletions
|
@ -9,6 +9,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -111,13 +112,8 @@ func getSearchTerm(ctx *context.Context) string {
|
|||
|
||||
// https://github.com/NuGet/NuGet.Client/blob/dev/src/NuGet.Core/NuGet.Protocol/LegacyFeed/V2FeedQueryBuilder.cs
|
||||
func SearchServiceV2(ctx *context.Context) {
|
||||
skip, take := ctx.FormInt("skip"), ctx.FormInt("take")
|
||||
if skip == 0 {
|
||||
skip = ctx.FormInt("$skip")
|
||||
}
|
||||
if take == 0 {
|
||||
take = ctx.FormInt("$top")
|
||||
}
|
||||
skip, take := ctx.FormInt("$skip"), ctx.FormInt("$top")
|
||||
paginator := db.NewAbsoluteListOptions(skip, take)
|
||||
|
||||
pvs, total, err := packages_model.SearchVersions(ctx, &packages_model.PackageSearchOptions{
|
||||
OwnerID: ctx.Package.Owner.ID,
|
||||
|
@ -126,10 +122,7 @@ func SearchServiceV2(ctx *context.Context) {
|
|||
Value: getSearchTerm(ctx),
|
||||
},
|
||||
IsInternal: util.OptionalBoolFalse,
|
||||
Paginator: db.NewAbsoluteListOptions(
|
||||
skip,
|
||||
take,
|
||||
),
|
||||
Paginator: paginator,
|
||||
})
|
||||
if err != nil {
|
||||
apiError(ctx, http.StatusInternalServerError, err)
|
||||
|
@ -142,8 +135,28 @@ func SearchServiceV2(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
skip, take = paginator.GetSkipTake()
|
||||
|
||||
var next *nextOptions
|
||||
if len(pvs) == take {
|
||||
next = &nextOptions{
|
||||
Path: "Search()",
|
||||
Query: url.Values{},
|
||||
}
|
||||
searchTerm := ctx.FormTrim("searchTerm")
|
||||
if searchTerm != "" {
|
||||
next.Query.Set("searchTerm", searchTerm)
|
||||
}
|
||||
filter := ctx.FormTrim("$filter")
|
||||
if filter != "" {
|
||||
next.Query.Set("$filter", filter)
|
||||
}
|
||||
next.Query.Set("$skip", strconv.Itoa(skip+take))
|
||||
next.Query.Set("$top", strconv.Itoa(take))
|
||||
}
|
||||
|
||||
resp := createFeedResponse(
|
||||
&linkBuilder{setting.AppURL + "api/packages/" + ctx.Package.Owner.Name + "/nuget"},
|
||||
&linkBuilder{Base: setting.AppURL + "api/packages/" + ctx.Package.Owner.Name + "/nuget", Next: next},
|
||||
total,
|
||||
pds,
|
||||
)
|
||||
|
@ -193,7 +206,7 @@ func SearchServiceV3(ctx *context.Context) {
|
|||
}
|
||||
|
||||
resp := createSearchResultResponse(
|
||||
&linkBuilder{setting.AppURL + "api/packages/" + ctx.Package.Owner.Name + "/nuget"},
|
||||
&linkBuilder{Base: setting.AppURL + "api/packages/" + ctx.Package.Owner.Name + "/nuget"},
|
||||
count,
|
||||
pds,
|
||||
)
|
||||
|
@ -222,7 +235,7 @@ func RegistrationIndex(ctx *context.Context) {
|
|||
}
|
||||
|
||||
resp := createRegistrationIndexResponse(
|
||||
&linkBuilder{setting.AppURL + "api/packages/" + ctx.Package.Owner.Name + "/nuget"},
|
||||
&linkBuilder{Base: setting.AppURL + "api/packages/" + ctx.Package.Owner.Name + "/nuget"},
|
||||
pds,
|
||||
)
|
||||
|
||||
|
@ -251,7 +264,7 @@ func RegistrationLeafV2(ctx *context.Context) {
|
|||
}
|
||||
|
||||
resp := createEntryResponse(
|
||||
&linkBuilder{setting.AppURL + "api/packages/" + ctx.Package.Owner.Name + "/nuget"},
|
||||
&linkBuilder{Base: setting.AppURL + "api/packages/" + ctx.Package.Owner.Name + "/nuget"},
|
||||
pd,
|
||||
)
|
||||
|
||||
|
@ -280,7 +293,7 @@ func RegistrationLeafV3(ctx *context.Context) {
|
|||
}
|
||||
|
||||
resp := createRegistrationLeafResponse(
|
||||
&linkBuilder{setting.AppURL + "api/packages/" + ctx.Package.Owner.Name + "/nuget"},
|
||||
&linkBuilder{Base: setting.AppURL + "api/packages/" + ctx.Package.Owner.Name + "/nuget"},
|
||||
pd,
|
||||
)
|
||||
|
||||
|
@ -291,7 +304,19 @@ func RegistrationLeafV3(ctx *context.Context) {
|
|||
func EnumeratePackageVersionsV2(ctx *context.Context) {
|
||||
packageName := strings.Trim(ctx.FormTrim("id"), "'")
|
||||
|
||||
pvs, err := packages_model.GetVersionsByPackageName(ctx, ctx.Package.Owner.ID, packages_model.TypeNuGet, packageName)
|
||||
skip, take := ctx.FormInt("$skip"), ctx.FormInt("$top")
|
||||
paginator := db.NewAbsoluteListOptions(skip, take)
|
||||
|
||||
pvs, total, err := packages_model.SearchVersions(ctx, &packages_model.PackageSearchOptions{
|
||||
OwnerID: ctx.Package.Owner.ID,
|
||||
Type: packages_model.TypeNuGet,
|
||||
Name: packages_model.SearchValue{
|
||||
ExactMatch: true,
|
||||
Value: packageName,
|
||||
},
|
||||
IsInternal: util.OptionalBoolFalse,
|
||||
Paginator: paginator,
|
||||
})
|
||||
if err != nil {
|
||||
apiError(ctx, http.StatusInternalServerError, err)
|
||||
return
|
||||
|
@ -303,9 +328,22 @@ func EnumeratePackageVersionsV2(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
skip, take = paginator.GetSkipTake()
|
||||
|
||||
var next *nextOptions
|
||||
if len(pvs) == take {
|
||||
next = &nextOptions{
|
||||
Path: "FindPackagesById()",
|
||||
Query: url.Values{},
|
||||
}
|
||||
next.Query.Set("id", packageName)
|
||||
next.Query.Set("$skip", strconv.Itoa(skip+take))
|
||||
next.Query.Set("$top", strconv.Itoa(take))
|
||||
}
|
||||
|
||||
resp := createFeedResponse(
|
||||
&linkBuilder{setting.AppURL + "api/packages/" + ctx.Package.Owner.Name + "/nuget"},
|
||||
int64(len(pds)),
|
||||
&linkBuilder{Base: setting.AppURL + "api/packages/" + ctx.Package.Owner.Name + "/nuget", Next: next},
|
||||
total,
|
||||
pds,
|
||||
)
|
||||
|
||||
|
@ -345,13 +383,7 @@ func EnumeratePackageVersionsV3(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
pds, err := packages_model.GetPackageDescriptors(ctx, pvs)
|
||||
if err != nil {
|
||||
apiError(ctx, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
resp := createPackageVersionsResponse(pds)
|
||||
resp := createPackageVersionsResponse(pvs)
|
||||
|
||||
ctx.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue