Class: Packages::PackageFile

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

Constant Summary collapse

INSTALLABLE_STATUSES =
[:default].freeze

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Class Method Summary collapse

Instance Method Summary collapse

Methods included from FileStoreMounter

#update_file_store

Methods included from AfterCommitQueue

#run_after_commit, #run_after_commit_or_now

Methods inherited from ApplicationRecord

cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, 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 SensitiveSerializableHash

#serializable_hash

Class Method Details

.most_recent!Object


92
93
94
# File 'app/models/packages/package_file.rb', line 92

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.


110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'app/models/packages/package_file.rb', line 110

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


127
128
129
# File 'app/models/packages/package_file.rb', line 127

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