qualify ordery_by clauses when necessary, remove unnecessary order_by's, reported by Ludo, resulted in errors in sqlite

This commit is contained in:
Rob Vermaas 2011-04-01 07:40:06 +00:00
parent ffa4ba3b9e
commit fca3019c7b
3 changed files with 54 additions and 54 deletions

View file

@ -17,7 +17,7 @@ use Email::Sender::Transport::SMTP;
sub nixMachines { sub nixMachines {
my ($c) = @_; my ($c) = @_;
my $result = "# GENERATED BY HYDRA\n"; my $result = "# GENERATED BY HYDRA\n";
foreach my $machine ($c->model("DB::BuildMachines")->all) { foreach my $machine ($c->model("DB::BuildMachines")->all) {
if($machine->enabled) { if($machine->enabled) {
$result = $result . $machine->username . '@'. $machine->hostname . ' '; $result = $result . $machine->username . '@'. $machine->hostname . ' ';
@ -38,7 +38,7 @@ sub saveNixMachines {
open (NIXMACHINES, '>/etc/nix.machines') or die("Could not write to /etc/nix.machines"); open (NIXMACHINES, '>/etc/nix.machines') or die("Could not write to /etc/nix.machines");
print NIXMACHINES nixMachines($c); print NIXMACHINES nixMachines($c);
close (NIXMACHINES); close (NIXMACHINES);
} }
sub admin : Chained('/') PathPart('admin') CaptureArgs(0) { sub admin : Chained('/') PathPart('admin') CaptureArgs(0) {
@ -50,19 +50,19 @@ sub admin : Chained('/') PathPart('admin') CaptureArgs(0) {
sub index : Chained('admin') PathPart('') Args(0) { sub index : Chained('admin') PathPart('') Args(0) {
my ($self, $c) = @_; my ($self, $c) = @_;
$c->stash->{machines} = [$c->model('DB::BuildMachines')->search( $c->stash->{machines} = [$c->model('DB::BuildMachines')->search(
{}, {},
{ order_by => ["enabled DESC", "hostname"] { order_by => ["enabled DESC", "hostname"]
, '+select' => ["(select bs.stoptime from buildsteps as bs where bs.machine = (me.username || '\@' || me.hostname) and not bs.stoptime is null order by bs.stoptime desc limit 1)"] , '+select' => ["(select bs.stoptime from buildsteps as bs where bs.machine = (me.username || '\@' || me.hostname) and not bs.stoptime is null order by bs.stoptime desc limit 1)"]
, '+as' => ['idle'] , '+as' => ['idle']
})]; })];
$c->stash->{steps} = [ $c->model('DB::BuildSteps')->search( $c->stash->{steps} = [ $c->model('DB::BuildSteps')->search(
{ 'me.busy' => 1, 'schedulingInfo.busy' => 1 }, { 'me.busy' => 1, 'schedulingInfo.busy' => 1 },
{ join => [ 'schedulingInfo', 'build' ] { join => [ 'schedulingInfo', 'build' ]
, order_by => [ 'machine', 'outpath' ] , order_by => [ 'machine' ]
} ) ]; } ) ];
$c->stash->{template} = 'admin.tt'; $c->stash->{template} = 'admin.tt';
} }
sub updateUser { sub updateUser {
my ($c, $user) = @_; my ($c, $user) = @_;
@ -70,8 +70,8 @@ sub updateUser {
my $fullname = trim $c->request->params->{"fullname"}; my $fullname = trim $c->request->params->{"fullname"};
my $emailaddress = trim $c->request->params->{"emailaddress"}; my $emailaddress = trim $c->request->params->{"emailaddress"};
my $emailonerror = trim $c->request->params->{"emailonerror"}; my $emailonerror = trim $c->request->params->{"emailonerror"};
my $roles = $c->request->params->{"roles"} ; my $roles = $c->request->params->{"roles"} ;
$user->update( $user->update(
{ fullname => $fullname { fullname => $fullname
, emailaddress => $emailaddress , emailaddress => $emailaddress
@ -81,10 +81,10 @@ sub updateUser {
if(ref($roles) eq 'ARRAY') { if(ref($roles) eq 'ARRAY') {
for my $s (@$roles) { for my $s (@$roles) {
$user->userroles->create({ role => $s}) ; $user->userroles->create({ role => $s}) ;
} }
} else { } else {
$user->userroles->create({ role => $roles}) if defined $roles ; $user->userroles->create({ role => $roles}) if defined $roles ;
} }
} }
sub user : Chained('admin') PathPart('user') CaptureArgs(1) { sub user : Chained('admin') PathPart('user') CaptureArgs(1) {
@ -123,11 +123,11 @@ sub user_edit_submit : Chained('user') PathPart('submit') Args(0) {
} }
sub sendemail { sub sendemail {
my ($to, $subject, $body) = @_; my ($to, $subject, $body) = @_;
my $url = hostname_long; my $url = hostname_long;
my $sender = ($ENV{'USER'} || "hydra") . "@" . $url; my $sender = ($ENV{'USER'} || "hydra") . "@" . $url;
my $email = Email::Simple->create( my $email = Email::Simple->create(
header => [ header => [
To => $to, To => $to,
@ -145,7 +145,7 @@ sub reset_password : Chained('user') PathPart('reset-password') Args(0) {
# generate password # generate password
my $password = Crypt::RandPasswd->word(8,10); my $password = Crypt::RandPasswd->word(8,10);
# calculate hash # calculate hash
my $hashed = sha1_hex($password); my $hashed = sha1_hex($password);
@ -154,7 +154,7 @@ sub reset_password : Chained('user') PathPart('reset-password') Args(0) {
# send email # send email
sendemail( sendemail(
$c->user->emailaddress, $c->user->emailaddress,
"New password for Hydra", "New password for Hydra",
"Hi,\n\n". "Hi,\n\n".
"Your password has been reset. Your new password is '$password'.\n". "Your password has been reset. Your new password is '$password'.\n".
@ -213,13 +213,13 @@ sub updateMachine {
my $speedfactor = trim $c->request->params->{"speedfactor"}; my $speedfactor = trim $c->request->params->{"speedfactor"};
my $ssh_key = trim $c->request->params->{"ssh_key"}; my $ssh_key = trim $c->request->params->{"ssh_key"};
my $options = trim $c->request->params->{"options"}; my $options = trim $c->request->params->{"options"};
my $systems = $c->request->params->{"systems"} ; my $systems = $c->request->params->{"systems"} ;
error($c, "Invalid or empty username.") if $username eq ""; error($c, "Invalid or empty username.") if $username eq "";
error($c, "Max concurrent builds should be an integer > 0.") if $maxconcurrent eq "" || ! $maxconcurrent =~ m/[0-9]+/; error($c, "Max concurrent builds should be an integer > 0.") if $maxconcurrent eq "" || ! $maxconcurrent =~ m/[0-9]+/;
error($c, "Speed factor should be an integer > 0.") if $speedfactor eq "" || ! $speedfactor =~ m/[0-9]+/; error($c, "Speed factor should be an integer > 0.") if $speedfactor eq "" || ! $speedfactor =~ m/[0-9]+/;
error($c, "Invalid or empty SSH key.") if $ssh_key eq ""; error($c, "Invalid or empty SSH key.") if $ssh_key eq "";
$machine->update( $machine->update(
{ username => $username { username => $username
, maxconcurrent => $maxconcurrent , maxconcurrent => $maxconcurrent
@ -231,17 +231,17 @@ sub updateMachine {
if(ref($systems) eq 'ARRAY') { if(ref($systems) eq 'ARRAY') {
for my $s (@$systems) { for my $s (@$systems) {
$machine->buildmachinesystemtypes->create({ system => $s}) ; $machine->buildmachinesystemtypes->create({ system => $s}) ;
} }
} else { } else {
$machine->buildmachinesystemtypes->create({ system => $systems}) ; $machine->buildmachinesystemtypes->create({ system => $systems}) ;
} }
} }
sub create_machine : Chained('admin') PathPart('create-machine') Args(0) { sub create_machine : Chained('admin') PathPart('create-machine') Args(0) {
my ($self, $c) = @_; my ($self, $c) = @_;
requireAdmin($c); requireAdmin($c);
$c->stash->{template} = 'machine.tt'; $c->stash->{template} = 'machine.tt';
$c->stash->{systemtypes} = [$c->model('DB::SystemTypes')->search({}, {order_by => "system"})]; $c->stash->{systemtypes} = [$c->model('DB::SystemTypes')->search({}, {order_by => "system"})];
$c->stash->{edit} = 1; $c->stash->{edit} = 1;
@ -253,10 +253,10 @@ sub create_machine_submit : Chained('admin') PathPart('create-machine/submit') A
my ($self, $c) = @_; my ($self, $c) = @_;
requireAdmin($c); requireAdmin($c);
my $hostname = trim $c->request->params->{"hostname"}; my $hostname = trim $c->request->params->{"hostname"};
error($c, "Invalid or empty hostname.") if $hostname eq ""; error($c, "Invalid or empty hostname.") if $hostname eq "";
txn_do($c->model('DB')->schema, sub { txn_do($c->model('DB')->schema, sub {
my $machine = $c->model('DB::BuildMachines')->create( my $machine = $c->model('DB::BuildMachines')->create(
{ hostname => $hostname }); { hostname => $hostname });
@ -272,7 +272,7 @@ sub machine_delete : Chained('machine') PathPart('delete') Args(0) {
txn_do($c->model('DB')->schema, sub { txn_do($c->model('DB')->schema, sub {
$c->stash->{machine}->delete; $c->stash->{machine}->delete;
}); });
saveNixMachines($c); saveNixMachines($c);
$c->res->redirect("/admin/machines"); $c->res->redirect("/admin/machines");
} }
@ -304,7 +304,7 @@ sub clearvcscache : Chained('admin') Path('clear-vcs-cache') Args(0) {
print "Clearing path cache\n"; print "Clearing path cache\n";
$c->model('DB::CachedPathInputs')->delete_all; $c->model('DB::CachedPathInputs')->delete_all;
print "Clearing git cache\n"; print "Clearing git cache\n";
$c->model('DB::CachedGitInputs')->delete_all; $c->model('DB::CachedGitInputs')->delete_all;
@ -322,17 +322,17 @@ sub managenews : Chained('admin') Path('news') Args(0) {
$c->stash->{newsItems} = [$c->model('DB::NewsItems')->search({}, {order_by => 'createtime DESC'})]; $c->stash->{newsItems} = [$c->model('DB::NewsItems')->search({}, {order_by => 'createtime DESC'})];
$c->stash->{template} = 'news.tt'; $c->stash->{template} = 'news.tt';
} }
sub news_submit : Chained('admin') Path('news/submit') Args(0) { sub news_submit : Chained('admin') Path('news/submit') Args(0) {
my ($self, $c) = @_; my ($self, $c) = @_;
requirePost($c); requirePost($c);
my $contents = trim $c->request->params->{"contents"}; my $contents = trim $c->request->params->{"contents"};
my $createtime = time; my $createtime = time;
$c->model('DB::NewsItems')->create({ $c->model('DB::NewsItems')->create({
createtime => $createtime, createtime => $createtime,
contents => $contents, contents => $contents,
@ -350,13 +350,13 @@ sub news_delete : Chained('admin') Path('news/delete') Args(1) {
or notFound($c, "Newsitem with id $id doesn't exist."); or notFound($c, "Newsitem with id $id doesn't exist.");
$newsItem->delete; $newsItem->delete;
}); });
$c->res->redirect("/admin/news"); $c->res->redirect("/admin/news");
} }
sub force_eval : Chained('admin') Path('eval') Args(2) { sub force_eval : Chained('admin') Path('eval') Args(2) {
my ($self, $c, $projectName, $jobsetName) = @_; my ($self, $c, $projectName, $jobsetName) = @_;
my $project = $c->model('DB::Projects')->find($projectName) my $project = $c->model('DB::Projects')->find($projectName)
or notFound($c, "Project $projectName doesn't exist."); or notFound($c, "Project $projectName doesn't exist.");
@ -364,9 +364,9 @@ sub force_eval : Chained('admin') Path('eval') Args(2) {
$c->stash->{jobset_} = $project->jobsets->search({name => $jobsetName}); $c->stash->{jobset_} = $project->jobsets->search({name => $jobsetName});
$c->stash->{jobset} = $c->stash->{jobset_}->single $c->stash->{jobset} = $c->stash->{jobset_}->single
or notFound($c, "Jobset $jobsetName doesn't exist."); or notFound($c, "Jobset $jobsetName doesn't exist.");
(my $res, my $stdout, my $stderr) = captureStdoutStderr(60, ("hydra_evaluator.pl", $projectName, $jobsetName)); (my $res, my $stdout, my $stderr) = captureStdoutStderr(60, ("hydra_evaluator.pl", $projectName, $jobsetName));
$c->res->redirect("/project/$projectName"); $c->res->redirect("/project/$projectName");
} }

View file

@ -15,7 +15,7 @@ sub begin :Private {
my ($self, $c, @args) = @_; my ($self, $c, @args) = @_;
$c->stash->{curUri} = $c->request->uri; $c->stash->{curUri} = $c->request->uri;
$c->stash->{version} = $ENV{"HYDRA_RELEASE"} || "<devel>"; $c->stash->{version} = $ENV{"HYDRA_RELEASE"} || "<devel>";
$c->stash->{nixVersion} = $ENV{"NIX_RELEASE"} || "<devel>"; $c->stash->{nixVersion} = $ENV{"NIX_RELEASE"} || "<devel>";
$c->stash->{curTime} = time; $c->stash->{curTime} = time;
if (scalar(@args) == 0 || $args[0] ne "static") { if (scalar(@args) == 0 || $args[0] ne "static") {
@ -37,7 +37,7 @@ sub index :Path :Args(0) {
sub login :Local { sub login :Local {
my ($self, $c) = @_; my ($self, $c) = @_;
my $username = $c->request->params->{username} || ""; my $username = $c->request->params->{username} || "";
my $password = $c->request->params->{password} || ""; my $password = $c->request->params->{password} || "";
@ -58,7 +58,7 @@ sub login :Local {
} }
$c->stash->{errorMsg} = "Bad username or password."; $c->stash->{errorMsg} = "Bad username or password.";
} }
$c->stash->{template} = 'login.tt'; $c->stash->{template} = 'login.tt';
} }
@ -82,7 +82,7 @@ sub queue :Local {
sub timeline :Local { sub timeline :Local {
my ($self, $c) = @_; my ($self, $c) = @_;
my $pit = time(); my $pit = time();
$c->stash->{pit} = $pit; $c->stash->{pit} = $pit;
$pit = $pit-(24*60*60)-1; $pit = $pit-(24*60*60)-1;
$c->stash->{template} = 'timeline.tt'; $c->stash->{template} = 'timeline.tt';
@ -90,8 +90,8 @@ sub timeline :Local {
{finished => 1, stoptime => { '>' => $pit } } {finished => 1, stoptime => { '>' => $pit } }
, { join => 'resultInfo' , { join => 'resultInfo'
, order_by => ["starttime"] , order_by => ["starttime"]
, '+select' => [ 'resultInfo.starttime', 'resultInfo.stoptime', 'resultInfo.buildstatus' ] , '+select' => [ 'resultInfo.starttime', 'resultInfo.stoptime', 'resultInfo.buildstatus' ]
, '+as' => [ 'starttime', 'stoptime', 'buildstatus' ] , '+as' => [ 'starttime', 'stoptime', 'buildstatus' ]
})]; })];
} }
@ -100,8 +100,8 @@ sub status :Local {
my ($self, $c) = @_; my ($self, $c) = @_;
$c->stash->{steps} = [ $c->model('DB::BuildSteps')->search( $c->stash->{steps} = [ $c->model('DB::BuildSteps')->search(
{ 'me.busy' => 1, 'schedulingInfo.busy' => 1 }, { 'me.busy' => 1, 'schedulingInfo.busy' => 1 },
{ join => [ 'schedulingInfo', 'build' ] { join => [ 'schedulingInfo', 'build' ]
, order_by => [ 'machine', 'outpath' ] , order_by => [ 'machine' ]
} ) ]; } ) ];
} }
@ -158,12 +158,12 @@ sub robots_txt : Path('robots.txt') {
, channelUris('Job', ["*", "*", "*", "*"]) , channelUris('Job', ["*", "*", "*", "*"])
, channelUris('Build', ["*"]) , channelUris('Build', ["*"])
); );
$c->stash->{'plain'} = { data => "User-agent: *\n" . join('', map { "Disallow: $_\n" } @rules) }; $c->stash->{'plain'} = { data => "User-agent: *\n" . join('', map { "Disallow: $_\n" } @rules) };
$c->forward('Hydra::View::Plain'); $c->forward('Hydra::View::Plain');
} }
sub default :Path { sub default :Path {
my ($self, $c) = @_; my ($self, $c) = @_;
notFound($c, "Page not found."); notFound($c, "Page not found.");
@ -201,27 +201,27 @@ sub nar :Local :Args(1) {
sub change_password : Path('change-password') : Args(0) { sub change_password : Path('change-password') : Args(0) {
my ($self, $c) = @_; my ($self, $c) = @_;
requireLogin($c) if !$c->user_exists; requireLogin($c) if !$c->user_exists;
$c->stash->{template} = 'change-password.tt'; $c->stash->{template} = 'change-password.tt';
} }
sub change_password_submit : Path('change-password/submit') : Args(0) { sub change_password_submit : Path('change-password/submit') : Args(0) {
my ($self, $c) = @_; my ($self, $c) = @_;
requireLogin($c) if !$c->user_exists; requireLogin($c) if !$c->user_exists;
my $password = $c->request->params->{"password"}; my $password = $c->request->params->{"password"};
my $password_check = $c->request->params->{"password_check"}; my $password_check = $c->request->params->{"password_check"};
print STDERR "$password \n"; print STDERR "$password \n";
print STDERR "$password_check \n"; print STDERR "$password_check \n";
error($c, "Passwords did not match, go back and try again!") if $password ne $password_check; error($c, "Passwords did not match, go back and try again!") if $password ne $password_check;
my $hashed = sha1_hex($password); my $hashed = sha1_hex($password);
$c->user->update({ password => $hashed}) ; $c->user->update({ password => $hashed}) ;
$c->res->redirect("/"); $c->res->redirect("/");
} }
1; 1;

View file

@ -46,12 +46,12 @@ foreach my $project ($db->resultset('Projects')->all) {
print STDERR "*** skipping disabled jobset ", $project->name, ":", $jobset->name, "\n"; print STDERR "*** skipping disabled jobset ", $project->name, ":", $jobset->name, "\n";
next; next;
} }
if ($keepnr <= 0 ) { if ($keepnr <= 0 ) {
print STDERR "*** jobset ", $project->name, ":", $jobset->name, " set to keep 0 builds\n"; print STDERR "*** jobset ", $project->name, ":", $jobset->name, " set to keep 0 builds\n";
next; next;
} }
# Go over all jobs in this jobset. # Go over all jobs in this jobset.
foreach my $job ($jobset->jobs->all) { foreach my $job ($jobset->jobs->all) {
print STDERR "*** looking for builds to keep in job ", print STDERR "*** looking for builds to keep in job ",
@ -69,7 +69,7 @@ foreach my $project ($db->resultset('Projects')->all) {
, system => $system->system , system => $system->system
}, },
{ join => 'resultInfo' { join => 'resultInfo'
, order_by => 'id DESC' , order_by => 'me.id DESC'
, rows => $keepnr , rows => $keepnr
}); });
keepBuild $_ foreach @recentBuilds; keepBuild $_ foreach @recentBuilds;