diff options
author | KN4CK3R <admin@oldschoolhack.me> | 2022-10-16 19:18:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-17 01:18:09 +0800 |
commit | 11d3677818df64df6cc8386c498169101dbdbb13 (patch) | |
tree | 6adfab51b3b2a6c63f654eb0a3586b5a2b204138 /routers/api/packages/nuget | |
parent | cad9adeff41595ea32281dbc2918e653c3e3a839 (diff) | |
download | gitea-11d3677818df64df6cc8386c498169101dbdbb13.tar.gz gitea-11d3677818df64df6cc8386c498169101dbdbb13.zip |
Enforce grouped NuGet search results (#21442)
Fixes #21434
Added tests to enforce this behaviour.
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'routers/api/packages/nuget')
-rw-r--r-- | routers/api/packages/nuget/api_v3.go | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/routers/api/packages/nuget/api_v3.go b/routers/api/packages/nuget/api_v3.go index 552054f26b..bb3e447bd6 100644 --- a/routers/api/packages/nuget/api_v3.go +++ b/routers/api/packages/nuget/api_v3.go @@ -207,20 +207,13 @@ type SearchResultVersion struct { } func createSearchResultResponse(l *linkBuilder, totalHits int64, pds []*packages_model.PackageDescriptor) *SearchResultResponse { - data := make([]*SearchResult, 0, len(pds)) + grouped := make(map[string][]*packages_model.PackageDescriptor) + for _, pd := range pds { + grouped[pd.Package.Name] = append(grouped[pd.Package.Name], pd) + } - if len(pds) > 0 { - groupID := pds[0].Package.Name - group := make([]*packages_model.PackageDescriptor, 0, 10) - - for i := 0; i < len(pds); i++ { - if groupID != pds[i].Package.Name { - data = append(data, createSearchResult(l, group)) - groupID = pds[i].Package.Name - group = group[:0] - } - group = append(group, pds[i]) - } + data := make([]*SearchResult, 0, len(pds)) + for _, group := range grouped { data = append(data, createSearchResult(l, group)) } |