@@ -685,10 +685,9 @@ sub _calculate_preferred_machines ($jobs) {
685685}
686686
687687# Take an job objects arrayref and prepare data structures for 'overview'
688- sub _prepare_job_results ($self , $all_jobs , $limit ) {
688+ sub _prepare_job_results ($self , $jobs , $job_ids ) {
689689 my %archs ;
690690 my %results ;
691- my @job_ids ;
692691 my $aggregated = {
693692 none => 0,
694693 passed => 0,
@@ -699,25 +698,8 @@ sub _prepare_job_results ($self, $all_jobs, $limit) {
699698 running => 0,
700699 unknown => 0
701700 };
702- my $preferred_machines = _calculate_preferred_machines($all_jobs );
703-
704- # read parameter for additional filtering
705- my $failed_modules = $self -> param_hash(' failed_modules' );
706- my $states = $self -> param_hash(' state' );
707- my $results = $self -> param_hash(' result' );
708- my $archs = $self -> param_hash(' arch' );
709- my $machines = $self -> param_hash(' machine' );
710-
711- my @jobs = grep {
712- (not $states or $states -> {$_ -> state})
713- and (not $results or $results -> {$_ -> result})
714- and (not $archs or $archs -> {$_ -> ARCH})
715- and (not $machines or $machines -> {$_ -> MACHINE})
716- and (not $failed_modules or $_ -> result eq OpenQA::Jobs::Constants::FAILED)
717- } @$all_jobs ;
718- my $limit_exceeded = @jobs >= $limit ;
719- @jobs = @jobs [0 .. ($limit - 1)] if $limit_exceeded ;
720- my @jobids = map { $_ -> id } @jobs ;
701+ my @jobs = $jobs -> all;
702+ my $preferred_machines = _calculate_preferred_machines(\@jobs );
721703
722704 # prefetch the number of available labels for those jobs
723705 my $schema = $self -> schema;
@@ -726,7 +708,7 @@ sub _prepare_job_results ($self, $all_jobs, $limit) {
726708 # prefetch test suite names from job settings
727709 my $job_settings
728710 = $schema -> resultset(' JobSettings' )
729- -> search({job_id => {-in => [ map { $_ -> id } @jobs ] }, key => {-in => [qw( JOB_DESCRIPTION TEST_SUITE_NAME) ]}});
711+ -> search({job_id => {-in => $job_ids }, key => {-in => [qw( JOB_DESCRIPTION TEST_SUITE_NAME) ]}});
730712 my %settings_by_job_id ;
731713 for my $js ($job_settings -> all) {
732714 $settings_by_job_id {$js -> job_id}-> {$js -> key} = $js -> value;
@@ -740,12 +722,13 @@ sub _prepare_job_results ($self, $all_jobs, $limit) {
740722 = $schema -> resultset(' TestSuites' )-> search({name => \%desc_args }, {columns => [qw( name description) ]});
741723 my %descriptions = map { $_ -> name => $_ -> description } @descriptions ;
742724
743- my $failed_modules_by_job = $self -> _fetch_failed_modules_by_jobs(\ @jobids );
744- my ($children_by_job , $parents_by_job ) = $self -> _fetch_dependencies_by_jobs(\ @jobids );
725+ my $failed_modules_by_job = $self -> _fetch_failed_modules_by_jobs($job_ids );
726+ my ($children_by_job , $parents_by_job ) = $self -> _fetch_dependencies_by_jobs($job_ids );
745727 foreach my $job (@jobs ) {
746728 my $id = $job -> id;
747729 my $result = $job -> overview_result(
748- $comment_data , $aggregated , $failed_modules ,
730+ $comment_data , $aggregated ,
731+ $self -> param_hash(' failed_modules' ),
749732 $failed_modules_by_job -> {$id } || [],
750733 $self -> param(' todo' )) or next ;
751734 my $test = $job -> TEST;
@@ -780,14 +763,11 @@ sub _prepare_job_results ($self, $all_jobs, $limit) {
780763 $results {$distri }{$version }{$flavor }{$test } //= {};
781764 $results {$distri }{$version }{$flavor }{$test }{$arch } = $result ;
782765
783- # populate job IDs for adding multiple comments
784- push @job_ids , $id ;
785-
786766 # add description
787767 my $description = $settings_by_job_id {$id }-> {JOB_DESCRIPTION } // $descriptions {$test_suite_names {$id }};
788768 $results {$distri }{$version }{$flavor }{$test }{description } //= $description ;
789769 }
790- return ($limit_exceeded , \%archs , \%results , \ @job_ids , $aggregated );
770+ return (\%archs , \%results , $aggregated );
791771}
792772
793773sub _prepare_groupids ($self ) {
@@ -857,32 +837,26 @@ sub overview ($self) {
857837 my $validation = $self -> validation;
858838 $validation -> optional(' t' )-> datetime;
859839 my $until = $validation -> param(' t' );
860- my %stash = (
861- # build, version, distri are not mandatory and therefore not
862- # necessarily come from the search args so they can be undefined.
863- build => ref $search_args -> {build } eq ' ARRAY' ? join (' ,' , @{$search_args -> {build }}) : $search_args -> {build },
864- version => $search_args -> {version },
865- distri => $search_args -> {distri },
866- groups => $groups ,
867- until => $until ,
868- parallel_children_collapsable_results_sel => $config -> {global }-> {parallel_children_collapsable_results_sel },
869- );
870- my @jobs = $self -> schema-> resultset(' Jobs' )-> complex_query(%$search_args )-> latest_jobs($until );
871-
872- my $limit = $config -> {misc_limits }-> {tests_overview_max_jobs };
873- (my $limit_exceeded , $stash {archs }, $stash {results }, $stash {job_ids }, $stash {aggregated })
874- = $self -> _prepare_job_results(\@jobs , $limit );
840+ $search_args -> {until } = $until ;
841+ my $distri = $search_args -> {distri };
842+ my $version = $search_args -> {version };
843+ my $jobs_rs = $self -> schema-> resultset(' Jobs' );
844+ my $latest_job_ids = $jobs_rs -> complex_query_latest_ids(%$search_args );
845+ my $limit = $search_args -> {limit }; # one more than actual limit so we can check whether the limit was exceeded
846+ my $exceeded_limit = @$latest_job_ids >= $limit ? $limit - 1 : 0;
847+ my $jobs = $jobs_rs -> latest_jobs_from_ids($latest_job_ids , $limit );
848+ my ($archs , $results , $aggregated ) = $self -> _prepare_job_results($jobs , $latest_job_ids );
875849
876850 # determine distri/version from job results if not explicitly specified via search args
877- my @distris = keys %{ $stash { results }} ;
851+ my @distris = keys %$ results ;
878852 my $formatted_distri ;
879853 my $formatted_version ;
880854 my $only_distri = scalar @distris == 1;
881- if (!defined $stash { distri } && $only_distri ) {
855+ if (!defined $distri && $only_distri ) {
882856 $formatted_distri = $distris [0];
883- if (!defined $stash { version } ) {
884- my @versions = keys %{$stash { results } -> {$formatted_distri }};
885- $formatted_version = $versions [0] if ( scalar @versions == 1) ;
857+ if (!defined $version ) {
858+ my @versions = keys %{$results -> {$formatted_distri }};
859+ $formatted_version = $versions [0] if scalar @versions == 1;
886860 }
887861 }
888862
@@ -899,18 +873,28 @@ sub overview ($self) {
899873 _add_distri_and_version_to_summary(\@summary_parts , $formatted_distri , $formatted_version , 1);
900874
901875 # add distri and version from query parameters as regular strings
902- _add_distri_and_version_to_summary(\@summary_parts , $stash { distri } , $stash { version } , 0);
876+ _add_distri_and_version_to_summary(\@summary_parts , $distri , $version , 0);
903877 }
904878
905- $self -> stash(
906- %stash ,
879+ my %stash = (
880+ # build, version, distri are not mandatory and therefore not
881+ # necessarily come from the search args so they can be undefined.
882+ build => ref $search_args -> {build } eq ' ARRAY' ? join (' ,' , @{$search_args -> {build }}) : $search_args -> {build },
883+ distri => $distri ,
884+ version => $version ,
885+ groups => $groups ,
886+ archs => $archs ,
887+ results => $results ,
888+ aggregated => $aggregated ,
889+ job_ids => $latest_job_ids ,
890+ until => $until ,
891+ parallel_children_collapsable_results_sel => $config -> {global }-> {parallel_children_collapsable_results_sel },
907892 summary_parts => \@summary_parts ,
908893 only_distri => $only_distri ,
909- limit_exceeded => $limit_exceeded ? $limit : undef
894+ limit_exceeded => $exceeded_limit ,
910895 );
911- $self -> respond_to(
912- json => {json => \%stash },
913- html => {template => ' test/overview' });
896+ $self -> stash(\%stash );
897+ $self -> respond_to(json => {json => \%stash }, html => {template => ' test/overview' });
914898}
915899
916900sub _get_latest_job ($self ) {
0 commit comments