diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-14 15:10:35 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-14 15:10:35 +0300 |
commit | d378fdaa60adb7217e3fc798580ad206127728d5 (patch) | |
tree | 9cb715513dd4d4197f76b2908458551940b0a094 /app/models/packages | |
parent | 7b69070a7468c4a9b6fe0ed7fbf1b3f2b58434e0 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/packages')
-rw-r--r-- | app/models/packages/package_file.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/app/models/packages/package_file.rb b/app/models/packages/package_file.rb index 807c6c409c7..14701b8a800 100644 --- a/app/models/packages/package_file.rb +++ b/app/models/packages/package_file.rb @@ -93,6 +93,24 @@ class Packages::PackageFile < ApplicationRecord skip_callback :commit, :after, :remove_previously_stored_file, if: :execute_move_in_object_storage? after_commit :move_in_object_storage, if: :execute_move_in_object_storage? + # Returns the most recent package files for *each* of the given packages. + # The order is not guaranteed. + def self.most_recent_for(packages, extra_join: nil, extra_where: nil) + cte_name = :packages_cte + cte = Gitlab::SQL::CTE.new(cte_name, packages.select(:id)) + + package_files = ::Packages::PackageFile.limit_recent(1) + .where(arel_table[:package_id].eq(Arel.sql("#{cte_name}.id"))) + + package_files = package_files.joins(extra_join) if extra_join + package_files = package_files.where(extra_where) if extra_where + + query = select('finder.*') + .from([Arel.sql(cte_name.to_s), package_files.arel.lateral.as('finder')]) + + query.with(cte.to_arel) + end + def download_path Gitlab::Routing.url_helpers.download_project_package_file_path(project, self) end |