diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-18 22:00:14 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-18 22:00:14 +0300 |
commit | 05f0ebba3a2c8ddf39e436f412dc2ab5bf1353b2 (patch) | |
tree | 11d0f2a6ec31c7793c184106cedc2ded3d9a2cc5 /app/models/ml/candidate.rb | |
parent | ec73467c23693d0db63a797d10194da9e72a74af (diff) |
Add latest changes from gitlab-org/gitlab@15-8-stable-eev15.8.0-rc42
Diffstat (limited to 'app/models/ml/candidate.rb')
-rw-r--r-- | app/models/ml/candidate.rb | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/app/models/ml/candidate.rb b/app/models/ml/candidate.rb index f24161d598f..3ea46a8b703 100644 --- a/app/models/ml/candidate.rb +++ b/app/models/ml/candidate.rb @@ -2,6 +2,8 @@ module Ml class Candidate < ApplicationRecord + PACKAGE_PREFIX = 'ml_candidate_' + enum status: { running: 0, scheduled: 1, finished: 2, failed: 3, killed: 4 } validates :iid, :experiment, presence: true @@ -16,20 +18,31 @@ module Ml attribute :iid, default: -> { SecureRandom.uuid } - scope :including_metrics_and_params, -> { includes(:latest_metrics, :params) } + scope :including_relationships, -> { includes(:latest_metrics, :params, :user) } + + delegate :project_id, :project, to: :experiment def artifact_root "/#{package_name}/#{package_version}/" end def artifact - ::Packages::Generic::PackageFinder.new(experiment.project).execute!(package_name, package_version) - rescue ActiveRecord::RecordNotFound - nil + artifact_lazy&.itself + end + + def artifact_lazy + BatchLoader.for(id).batch do |candidate_ids, loader| + Packages::Package + .joins("INNER JOIN ml_candidates ON packages_packages.name=(concat('#{PACKAGE_PREFIX}', ml_candidates.id))") + .where(ml_candidates: { id: candidate_ids }) + .find_each do |package| + loader.call(package.name.delete_prefix(PACKAGE_PREFIX).to_i, package) + end + end end def package_name - "ml_candidate_#{iid}" + "#{PACKAGE_PREFIX}#{id}" end def package_version |