diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 13:00:54 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 13:00:54 +0300 |
commit | 3cccd102ba543e02725d247893729e5c73b38295 (patch) | |
tree | f36a04ec38517f5deaaacb5acc7d949688d1e187 /app/finders/releases/group_releases_finder.rb | |
parent | 205943281328046ef7b4528031b90fbda70c75ac (diff) |
Add latest changes from gitlab-org/gitlab@14-10-stable-eev14.10.0-rc42
Diffstat (limited to 'app/finders/releases/group_releases_finder.rb')
-rw-r--r-- | app/finders/releases/group_releases_finder.rb | 44 |
1 files changed, 9 insertions, 35 deletions
diff --git a/app/finders/releases/group_releases_finder.rb b/app/finders/releases/group_releases_finder.rb index d87ba8c0b03..8b1b0c552fd 100644 --- a/app/finders/releases/group_releases_finder.rb +++ b/app/finders/releases/group_releases_finder.rb @@ -6,9 +6,8 @@ module Releases # # order_by - only ordering by released_at is supported # filter by tag - currently not supported + # include_subgroups - always true for group releases finder class GroupReleasesFinder - include Gitlab::Utils::StrongMemoize - attr_reader :parent, :current_user, :params def initialize(parent, current_user = nil, params = {}) @@ -16,59 +15,34 @@ module Releases @current_user = current_user @params = params - params[:order_by] ||= 'released_at' params[:sort] ||= 'desc' - params[:page] ||= 0 - params[:per] ||= 30 end def execute(preload: true) return Release.none unless Ability.allowed?(current_user, :read_release, parent) - releases = get_releases(preload: preload) - - paginate_releases(releases) + releases = get_releases + releases.preloaded if preload + releases end private - def include_subgroups? - params.fetch(:include_subgroups, false) - end - - def accessible_projects_scope - if include_subgroups? - Project.for_group_and_its_subgroups(parent) - else - parent.projects - end - end - # rubocop: disable CodeReuse/ActiveRecord - def get_releases(preload: true) + def get_releases Gitlab::Pagination::Keyset::InOperatorOptimization::QueryBuilder.new( - scope: releases_scope(preload: preload), - array_scope: accessible_projects_scope.select(:id), + scope: releases_scope, + array_scope: Project.for_group_and_its_subgroups(parent).select(:id), array_mapping_scope: -> (project_id_expression) { Release.where(Release.arel_table[:project_id].eq(project_id_expression)) }, finder_query: -> (order_by, id_expression) { Release.where(Release.arel_table[:id].eq(id_expression)) } ) .execute end - def releases_scope(preload: true) - scope = Release.all - scope = order_releases(scope) - scope = scope.preloaded if preload - scope - end - - def order_releases(scope) - scope.sort_by_attribute("released_at_#{params[:sort]}").order(id: params[:sort]) + def releases_scope + Release.sort_by_attribute("released_at_#{params[:sort]}").order(id: params[:sort]) end - def paginate_releases(releases) - releases.page(params[:page].to_i).per(params[:per]) - end # rubocop: enable CodeReuse/ActiveRecord end end |