Class: Packages::Maven::GroupsAndProjectsPackageFilesFinder

Inherits:
Object
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
app/finders/packages/maven/groups_and_projects_package_files_finder.rb

Constant Summary collapse

MAX_IDS_COUNT =

main client of this finder is the maven virtual registry. Given the restrictions on the maven upstreams in a registry, that client will send max 20 ids.

20

Instance Method Summary collapse

Constructor Details

#initialize(path:, project_ids: [], group_ids: []) ⇒ GroupsAndProjectsPackageFilesFinder

Returns a new instance of GroupsAndProjectsPackageFilesFinder.



13
14
15
16
17
# File 'app/finders/packages/maven/groups_and_projects_package_files_finder.rb', line 13

def initialize(path:, project_ids: [], group_ids: [])
  @project_ids = project_ids
  @group_ids = group_ids
  @path = path
end

Instance Method Details

#executeObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/finders/packages/maven/groups_and_projects_package_files_finder.rb', line 19

def execute
  return ::Packages::PackageFile.none unless valid?

  # rubocop: disable CodeReuse/ActiveRecord -- highly specific query
  inner_query = ::Packages::PackageFile
    .with(metadatum_cte.to_arel)
    .installable
    .for_package_ids(packages)
    .with_file_name(filename)
    .select('DISTINCT ON (package_id) packages_package_files.*')
    .reorder('package_id, id DESC')
    .limit(MAX_IDS_COUNT)

  ::Packages::PackageFile
    .from(inner_query, :packages_package_files)
    .reorder(id: :desc)
  # rubocop: enable CodeReuse/ActiveRecord
end