diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-31 09:09:30 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-31 09:09:30 +0300 |
commit | e6c495fe40320eb01bf8c4fb132c9f22449ae9d2 (patch) | |
tree | add32dcc4b186baf21b77431ce5718e0b7cdbf36 /app/models/ml/candidate.rb | |
parent | 25805c16335ed6466f0e475417e3005cd09848c2 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/ml/candidate.rb')
-rw-r--r-- | app/models/ml/candidate.rb | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/app/models/ml/candidate.rb b/app/models/ml/candidate.rb index 16e49305fde..f973b00c568 100644 --- a/app/models/ml/candidate.rb +++ b/app/models/ml/candidate.rb @@ -24,8 +24,26 @@ module Ml scope :by_name, ->(name) { where("ml_candidates.name LIKE ?", "%#{sanitize_sql_like(name)}%") } # rubocop:disable GitlabSecurity/SqlInjection scope :order_by_metric, ->(metric, direction) do subquery = Ml::CandidateMetric.latest.where(name: metric) + column_expression = Arel::Table.new('latest')[:value] + metric_order_expression = direction.to_sym == :desc ? column_expression.desc : column_expression.asc + joins("INNER JOIN (#{subquery.to_sql}) latest ON latest.candidate_id = ml_candidates.id") - .order("latest.value #{direction}, ml_candidates.id DESC") + .select("ml_candidates.*", "latest.value as metric_value") + .order( + Gitlab::Pagination::Keyset::Order.build( + [ + Gitlab::Pagination::Keyset::ColumnOrderDefinition.new( + attribute_name: 'metric_value', + order_expression: metric_order_expression, + nullable: :nulls_last, + distinct: false + ), + Gitlab::Pagination::Keyset::ColumnOrderDefinition.new( + attribute_name: 'id', + order_expression: arel_table[:id].desc + ) + ]) + ) end delegate :project_id, :project, to: :experiment |