Skip to content

Commit c331405

Browse files
committed
Implement build version sorting by oldest job in build
1 parent 79e3f49 commit c331405

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

lib/OpenQA/BuildResults.pm

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package OpenQA::BuildResults;
66
use Mojo::Base -strict, -signatures;
77

88
use OpenQA::Jobs::Constants;
9+
use OpenQA::Constants qw(BUILD_SORT_BY_NAME BUILD_SORT_BY_NEWEST_JOB BUILD_SORT_BY_OLDEST_JOB);
910
use OpenQA::Schema::Result::Jobs;
1011
use OpenQA::Utils;
1112
use OpenQA::Log qw(log_error);
@@ -131,13 +132,18 @@ sub compute_build_results ($group, $limit, $time_limit_days, $tags, $subgroup_fi
131132
return \%result;
132133
}
133134

135+
# build sorting
136+
my $buildver_sort_mode = BUILD_SORT_BY_NAME;
137+
$buildver_sort_mode = $group->build_version_sort if $group->can('build_version_sort');
138+
my $sort_column = $buildver_sort_mode == BUILD_SORT_BY_OLDEST_JOB ? 'oldest_job' : 'newest_job';
139+
134140
# 400 is the max. limit selectable in the group overview
135141
my $row_limit = (defined($limit) && $limit > 400) ? $limit : 400;
136142
my @search_cols = qw(VERSION BUILD);
137143
my %search_opts = (
138-
select => [@search_cols, {max => 'id', -as => 'lasted_job'}],
144+
select => [@search_cols, {max => 'id', -as => 'newest_job'}, {min => 'id', -as => 'oldest_job'}],
139145
group_by => \@search_cols,
140-
order_by => {-desc => 'lasted_job'},
146+
order_by => {-desc => $sort_column},
141147
rows => $row_limit
142148
);
143149
my %search_filter = (group_id => {in => $group_ids});
@@ -169,12 +175,7 @@ sub compute_build_results ($group, $limit, $time_limit_days, $tags, $subgroup_fi
169175
$build->{key} = join('-', $version, $buildnr);
170176
$versions_per_build{$buildnr}->{$version} = 1;
171177
}
172-
# sort by treating the key as a version number, if job group
173-
# indicates this is OK (the default). otherwise, list remains
174-
# sorted on the most recent job for each build
175-
my $versort = 1;
176-
$versort = $group->build_version_sort if $group->can('build_version_sort');
177-
if ($versort) {
178+
if ($buildver_sort_mode == BUILD_SORT_BY_NAME) {
178179
@builds = reverse sort { versioncmp($a->{key}, $b->{key}); } @builds;
179180
}
180181

0 commit comments

Comments
 (0)