Commit 1b8e1e43 authored by James Lopez's avatar James Lopez

Merge branch '207213-fix-nuget-search' into 'master'

Nuget search: fix the prerelease filtering

See merge request gitlab-org/gitlab!29482
parents 513ce4c0 7426318a
...@@ -8,6 +8,7 @@ module Packages ...@@ -8,6 +8,7 @@ module Packages
MAX_PER_PAGE = 30 MAX_PER_PAGE = 30
MAX_VERSIONS_PER_PACKAGE = 10 MAX_VERSIONS_PER_PACKAGE = 10
PRE_RELEASE_VERSION_MATCHING_TERM = '%-%'
DEFAULT_OPTIONS = { DEFAULT_OPTIONS = {
include_prerelease_versions: true, include_prerelease_versions: true,
...@@ -38,18 +39,20 @@ module Packages ...@@ -38,18 +39,20 @@ module Packages
# See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/24182#technical-notes # See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/24182#technical-notes
# and https://docs.microsoft.com/en-us/nuget/api/search-query-service-resource # and https://docs.microsoft.com/en-us/nuget/api/search-query-service-resource
subquery_name = :partition_subquery subquery_name = :partition_subquery
arel_table = Arel::Table.new(:partition_subquery)
column_names = Packages::Package.column_names.map do |cn| column_names = Packages::Package.column_names.map do |cn|
"#{subquery_name}.#{quote_column_name(cn)}" "#{subquery_name}.#{quote_column_name(cn)}"
end end
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
Packages::Package.select(column_names.join(',')) pkgs = Packages::Package.select(column_names.join(','))
.from(package_names_partition, subquery_name) .from(package_names_partition, subquery_name)
.where( .where(arel_table[:row_number].lteq(MAX_VERSIONS_PER_PACKAGE))
"#{subquery_name}.row_number <= :max_versions_count",
max_versions_count: MAX_VERSIONS_PER_PACKAGE return pkgs if include_prerelease_versions?
)
# rubocop: enable CodeReuse/ActiveRecord # we can't use pkgs.without_version_like since we have a custom from
pkgs.where.not(arel_table[:version].matches(PRE_RELEASE_VERSION_MATCHING_TERM))
end end
def package_names_partition def package_names_partition
...@@ -74,7 +77,7 @@ module Packages ...@@ -74,7 +77,7 @@ module Packages
.without_nuget_temporary_name .without_nuget_temporary_name
.order_name .order_name
.select_distinct_name .select_distinct_name
pkgs = pkgs.without_version_like('%-%') unless include_prerelease_versions? pkgs = pkgs.without_version_like(PRE_RELEASE_VERSION_MATCHING_TERM) unless include_prerelease_versions?
pkgs = pkgs.search_by_name(@search_term) if @search_term.present? pkgs = pkgs.search_by_name(@search_term) if @search_term.present?
pkgs.page(0) # we're using a padding pkgs.page(0) # we're using a padding
.per(per_page) .per(per_page)
......
---
title: 'Nuget search: fix the prerelease filtering'
merge_request: 29482
author:
type: fixed
...@@ -97,6 +97,12 @@ describe Packages::Nuget::SearchService do ...@@ -97,6 +97,12 @@ describe Packages::Nuget::SearchService do
let(:include_prerelease_versions) { false } let(:include_prerelease_versions) { false }
it { expect_search_results 3, package_a, packages_b, packages_c } it { expect_search_results 3, package_a, packages_b, packages_c }
context 'when mixed with release versions' do
let_it_be(:package_e_release) { create(:nuget_package, project: project, name: 'DummyPackageE', version: '3.2.1') }
it { expect_search_results 4, package_a, packages_b, packages_c, package_e_release }
end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment