diff options
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 |