Class: Packages::PackageFile

Inherits:
ApplicationRecord show all
Includes:
AfterCommitQueue, FileStoreMounter, ObjectStorable, Destructible, Installable, UpdateProjectStatistics
Defined in:
app/models/packages/package_file.rb

Constant Summary collapse

STORE_COLUMN =
:file_store
INSTALLABLE_STATUSES =
[:default].freeze
ENCODED_SLASH =
"%2F"
SORTABLE_COLUMNS =
%w[id file_name created_at].freeze

Constants included from FileStoreMounter

FileStoreMounter::ALLOWED_FILE_FIELDS

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from HasCheckConstraints

HasCheckConstraints::NOT_NULL_CHECK_PATTERN

Constants included from ResetOnColumnErrors

ResetOnColumnErrors::MAX_RESET_PERIOD

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AfterCommitQueue

#run_after_commit, #run_after_commit_or_now

Methods inherited from ApplicationRecord

===, cached_column_list, #create_or_load_association, current_transaction, declarative_enum, default_select_columns, delete_all_returning, #deleted_from_database?, id_in, id_not_in, iid_in, nullable_column?, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from Organizations::Sharding

#sharding_organization

Methods included from ResetOnColumnErrors

#reset_on_union_error, #reset_on_unknown_attribute_error

Methods included from Gitlab::SensitiveSerializableHash

#serializable_hash

Class Method Details

.installable_statusesObject



184
185
186
# File 'app/models/packages/package_file.rb', line 184

def self.installable_statuses
  INSTALLABLE_STATUSES
end

.most_recent!Object



149
150
151
# File 'app/models/packages/package_file.rb', line 149

def self.most_recent!
  recent.first!
end

.most_recent_for(packages, extra_join: nil, extra_where: nil) ⇒ Object

Returns the most recent installable package file for each of the given packages. The order is not guaranteed.



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'app/models/packages/package_file.rb', line 167

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.installable
                                         .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

Instance Method Details

#download_pathObject



188
189
190
# File 'app/models/packages/package_file.rb', line 188

def download_path
  Gitlab::Routing.url_helpers.download_project_package_file_path(project, self)
end

#file_name_for_downloadObject



192
193
194
# File 'app/models/packages/package_file.rb', line 192

def file_name_for_download
  file_name.split(ENCODED_SLASH)[-1]
end