Ensure that each eval is compared to the previous one from the same jobset

Also, reduce the number of database hits.
This commit is contained in:
Eelco Dolstra 2013-02-26 19:08:39 +01:00
parent 1007735364
commit d1c2771ab8

View file

@ -288,60 +288,89 @@ sub getMainOutput {
} }
sub getEvalInputs {
my ($c, $eval) = @_;
my @inputs = $eval->jobsetevalinputs->search(
{ -or => [ -and => [ uri => { '!=' => undef }, revision => { '!=' => undef }], dependency => { '!=' => undef }], altNr => 0 },
{ order_by => "name" });
}
sub getEvalInfo {
my ($cache, $eval) = @_;
my $res = $cache->{$eval->id}; return $res if defined $res;
# Get stats for this eval.
my $nrScheduled;
my $nrSucceeded = $eval->nrsucceeded;
if (defined $nrSucceeded) {
$nrScheduled = 0;
} else {
$nrScheduled = $eval->builds->search({finished => 0})->count;
$nrSucceeded = $eval->builds->search({finished => 1, buildStatus => 0})->count;
if ($nrScheduled == 0) {
$eval->update({nrsucceeded => $nrSucceeded});
}
}
# Get the inputs.
my @inputsList = $eval->jobsetevalinputs->search(
{ -or => [ -and => [ uri => { '!=' => undef }, revision => { '!=' => undef }], dependency => { '!=' => undef }], altNr => 0 },
{ order_by => "name" });
my $inputs;
$inputs->{$_->name} = $_ foreach @inputsList;
return $cache->{$eval->id} =
{ nrScheduled => $nrScheduled
, nrSucceeded => $nrSucceeded
, inputs => $inputs
};
}
sub getEvals { sub getEvals {
my ($self, $c, $evals, $offset, $rows) = @_; my ($self, $c, $evals, $offset, $rows) = @_;
my @evals = $evals->search( my @evals = $evals->search(
{ hasnewbuilds => 1 }, { hasnewbuilds => 1 },
{ order_by => "id DESC", rows => $rows + 1, offset => $offset }); { order_by => "id DESC", rows => $rows, offset => $offset });
my @res = (); my @res = ();
my $prevInputs = []; my $cache = {};
my $prev;
for (my $n = scalar @evals - 1; $n >= 0; $n--) {
my $cur = $evals[$n];
# Get stats for this eval. foreach my $curEval (@evals) {
my $nrScheduled;
my $nrSucceeded = $cur->nrsucceeded; my ($prevEval) = $c->model('DB::JobsetEvals')->search(
if (defined $nrSucceeded) { { project => $curEval->get_column('project'), jobset => $curEval->get_column('jobset')
$nrScheduled = 0; , hasnewbuilds => 1, id => { '<', $curEval->id } },
} else { { order_by => "id DESC", rows => 1 });
$nrScheduled = $cur->builds->search({finished => 0})->count;
$nrSucceeded = $cur->builds->search({finished => 1, buildStatus => 0})->count; my $curInfo = getEvalInfo($cache, $curEval);
if ($nrScheduled == 0) { my $prevInfo = getEvalInfo($cache, $prevEval) if defined $prevEval;
$cur->update({nrsucceeded => $nrSucceeded});
}
}
# Compute what inputs changed between each eval. # Compute what inputs changed between each eval.
my $curInputs = [ $cur->jobsetevalinputs->search(
{ -or => [ -and => [ uri => { '!=' => undef }, revision => { '!=' => undef }], dependency => { '!=' => undef }], altNr => 0 },
{ order_by => "name" }) ];
my @changedInputs; my @changedInputs;
my %prevInputsHash; foreach my $input (values %{$curInfo->{inputs}}) {
$prevInputsHash{$_->name} = $_ foreach @{$prevInputs}; my $p = $prevInfo->{inputs}->{$input->name};
foreach my $input (@{$curInputs}) { push @changedInputs, $input if
my $p = $prevInputsHash{$input->name}; !defined $p
push @changedInputs, $input || ($input->revision || "") ne ($p->revision || "")
if !defined $p || ($input->revision || "") ne ($p->revision || "") || $input->type ne $p->type || ($input->uri || "") ne ($p->uri || "") || || $input->type ne $p->type
( defined $input->dependency && defined $p->dependency && $input->dependency->id ne $p->dependency->id); || ($input->uri || "") ne ($p->uri || "")
|| ($input->get_column('dependency') || "") ne ($p->get_column('dependency') || "");
} }
$prevInputs = $curInputs;
my $e = push @res,
{ eval => $cur { eval => $curEval
, nrScheduled => $nrScheduled , nrScheduled => $curInfo->{nrScheduled}
, nrSucceeded => $nrSucceeded , nrSucceeded => $curInfo->{nrSucceeded}
, nrFailed => $cur->nrbuilds - $nrSucceeded - $nrScheduled , nrFailed => $curEval->nrbuilds - $curInfo->{nrSucceeded} - $curInfo->{nrScheduled}
, diff => defined $prev ? $nrSucceeded - $prev->{nrSucceeded} : 0 , diff => defined $prevEval ? $curInfo->{nrSucceeded} - $prevInfo->{nrSucceeded} : 0
, changedInputs => [ @changedInputs ] , changedInputs => [ @changedInputs ]
}; };
push @res, $e if $n < $rows;
$prev = $e;
} }
return [reverse @res]; return [@res];
} }