diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-06 21:13:45 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-06 21:13:45 +0300 |
commit | c38fb401d2e0348c0dbfd415c9818444dbe4951c (patch) | |
tree | aee27d8fd8758356c73b6654011effa270eb0f3a /app/models/packages | |
parent | f20be8802a40405885e9421417809438e5772bf5 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/packages')
-rw-r--r-- | app/models/packages/debian/group_distribution.rb | 4 | ||||
-rw-r--r-- | app/models/packages/debian/project_distribution.rb | 1 | ||||
-rw-r--r-- | app/models/packages/package.rb | 8 | ||||
-rw-r--r-- | app/models/packages/package_file.rb | 25 |
4 files changed, 24 insertions, 14 deletions
diff --git a/app/models/packages/debian/group_distribution.rb b/app/models/packages/debian/group_distribution.rb index 50c1ec9f163..01938f4a2ec 100644 --- a/app/models/packages/debian/group_distribution.rb +++ b/app/models/packages/debian/group_distribution.rb @@ -12,8 +12,4 @@ class Packages::Debian::GroupDistribution < ApplicationRecord .for_projects(group.all_projects.public_only) .with_debian_codename(codename) end - - def package_files - ::Packages::PackageFile.for_package_ids(packages.select(:id)) - end end diff --git a/app/models/packages/debian/project_distribution.rb b/app/models/packages/debian/project_distribution.rb index 5ac60d789b3..73777e3b9d8 100644 --- a/app/models/packages/debian/project_distribution.rb +++ b/app/models/packages/debian/project_distribution.rb @@ -9,5 +9,4 @@ class Packages::Debian::ProjectDistribution < ApplicationRecord has_many :publications, class_name: 'Packages::Debian::Publication', inverse_of: :distribution, foreign_key: :distribution_id has_many :packages, class_name: 'Packages::Package', through: :publications - has_many :package_files, class_name: 'Packages::PackageFile', through: :packages end diff --git a/app/models/packages/package.rb b/app/models/packages/package.rb index ba6196cfc8d..ebb9774b875 100644 --- a/app/models/packages/package.rb +++ b/app/models/packages/package.rb @@ -5,6 +5,7 @@ class Packages::Package < ApplicationRecord include Gitlab::SQL::Pattern include UsageStatistics include Gitlab::Utils::StrongMemoize + include Packages::Installable DISPLAYABLE_STATUSES = [:default, :error].freeze INSTALLABLE_STATUSES = [:default, :hidden].freeze @@ -31,6 +32,9 @@ class Packages::Package < ApplicationRecord # package_files must be destroyed by ruby code in order to properly remove carrierwave uploads and update project statistics has_many :package_files, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent + # TODO: put the installable default scope on the :package_files association once the dependent: :destroy is removed + # See https://gitlab.com/gitlab-org/gitlab/-/issues/349191 + has_many :installable_package_files, -> { installable }, class_name: 'Packages::PackageFile', inverse_of: :package has_many :dependency_links, inverse_of: :package, class_name: 'Packages::DependencyLink' has_many :tags, inverse_of: :package, class_name: 'Packages::Tag' has_one :conan_metadatum, inverse_of: :package, class_name: 'Packages::Conan::Metadatum' @@ -100,9 +104,7 @@ class Packages::Package < ApplicationRecord scope :without_version_like, -> (version) { where.not(arel_table[:version].matches(version)) } scope :with_package_type, ->(package_type) { where(package_type: package_type) } scope :without_package_type, ->(package_type) { where.not(package_type: package_type) } - scope :with_status, ->(status) { where(status: status) } scope :displayable, -> { with_status(DISPLAYABLE_STATUSES) } - scope :installable, -> { with_status(INSTALLABLE_STATUSES) } scope :including_project_route, -> { includes(project: { namespace: :route }) } scope :including_tags, -> { includes(:tags) } scope :including_dependency_links, -> { includes(dependency_links: :dependency) } @@ -131,7 +133,7 @@ class Packages::Package < ApplicationRecord scope :without_nuget_temporary_name, -> { where.not(name: Packages::Nuget::TEMPORARY_PACKAGE_NAME) } scope :has_version, -> { where.not(version: nil) } - scope :preload_files, -> { preload(:package_files) } + scope :preload_files, -> { Feature.enabled?(:packages_installable_package_files) ? preload(:installable_package_files) : preload(:package_files) } scope :preload_pipelines, -> { preload(pipelines: :user) } scope :last_of_each_version, -> { where(id: all.select('MAX(id) AS id').group(:version)) } scope :limit_recent, ->(limit) { order_created_desc.limit(limit) } diff --git a/app/models/packages/package_file.rb b/app/models/packages/package_file.rb index 87c9f56cc41..34533a82ccd 100644 --- a/app/models/packages/package_file.rb +++ b/app/models/packages/package_file.rb @@ -2,12 +2,17 @@ class Packages::PackageFile < ApplicationRecord include UpdateProjectStatistics include FileStoreMounter + include Packages::Installable + + INSTALLABLE_STATUSES = [:default].freeze delegate :project, :project_id, to: :package delegate :conan_file_type, to: :conan_file_metadatum delegate :file_type, :dsc?, :component, :architecture, :fields, to: :debian_file_metadatum, prefix: :debian delegate :channel, :metadata, to: :helm_file_metadatum, prefix: :helm + enum status: { default: 0, pending_destruction: 1 } + belongs_to :package # used to move the linked file within object storage @@ -48,9 +53,12 @@ class Packages::PackageFile < ApplicationRecord end scope :for_helm_with_channel, ->(project, channel) do - joins(:package).merge(project.packages.helm.installable) - .joins(:helm_file_metadatum) - .where(packages_helm_file_metadata: { channel: channel }) + result = joins(:package) + .merge(project.packages.helm.installable) + .joins(:helm_file_metadatum) + .where(packages_helm_file_metadata: { channel: channel }) + result = result.installable if Feature.enabled?(:packages_installable_package_files) + result end scope :with_conan_file_type, ->(file_type) do @@ -94,14 +102,19 @@ 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. + # Returns the most recent installable package file 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 = if Feature.enabled?(:packages_installable_package_files) + ::Packages::PackageFile.installable.limit_recent(1) + .where(arel_table[:package_id].eq(Arel.sql("#{cte_name}.id"))) + else + ::Packages::PackageFile.limit_recent(1) + .where(arel_table[:package_id].eq(Arel.sql("#{cte_name}.id"))) + end package_files = package_files.joins(extra_join) if extra_join package_files = package_files.where(extra_where) if extra_where |