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 {
my ($c) = @_;
my $result = "# GENERATED BY HYDRA\n";
foreach my $machine ($c->model("DB::BuildMachines")->all) {
if($machine->enabled) {
$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");
print NIXMACHINES nixMachines($c);
close (NIXMACHINES);
close (NIXMACHINES);
}
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) {
my ($self, $c) = @_;
$c->stash->{machines} = [$c->model('DB::BuildMachines')->search(
{},
{},
{ 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)"]
, '+as' => ['idle']
})];
$c->stash->{steps} = [ $c->model('DB::BuildSteps')->search(
{ 'me.busy' => 1, 'schedulingInfo.busy' => 1 },
{ join => [ 'schedulingInfo', 'build' ]
, order_by => [ 'machine', 'outpath' ]
{ join => [ 'schedulingInfo', 'build' ]
, order_by => [ 'machine' ]
} ) ];
$c->stash->{template} = 'admin.tt';
}
sub updateUser {
my ($c, $user) = @_;
@ -70,8 +70,8 @@ sub updateUser {
my $fullname = trim $c->request->params->{"fullname"};
my $emailaddress = trim $c->request->params->{"emailaddress"};
my $emailonerror = trim $c->request->params->{"emailonerror"};
my $roles = $c->request->params->{"roles"} ;
my $roles = $c->request->params->{"roles"} ;
$user->update(
{ fullname => $fullname
, emailaddress => $emailaddress
@ -81,10 +81,10 @@ sub updateUser {
if(ref($roles) eq 'ARRAY') {
for my $s (@$roles) {
$user->userroles->create({ role => $s}) ;
}
}
} else {
$user->userroles->create({ role => $roles}) if defined $roles ;
}
}
}
sub user : Chained('admin') PathPart('user') CaptureArgs(1) {
@ -123,11 +123,11 @@ sub user_edit_submit : Chained('user') PathPart('submit') Args(0) {
}
sub sendemail {
my ($to, $subject, $body) = @_;
my ($to, $subject, $body) = @_;
my $url = hostname_long;
my $sender = ($ENV{'USER'} || "hydra") . "@" . $url;
my $email = Email::Simple->create(
header => [
To => $to,
@ -145,7 +145,7 @@ sub reset_password : Chained('user') PathPart('reset-password') Args(0) {
# generate password
my $password = Crypt::RandPasswd->word(8,10);
# calculate hash
my $hashed = sha1_hex($password);
@ -154,7 +154,7 @@ sub reset_password : Chained('user') PathPart('reset-password') Args(0) {
# send email
sendemail(
$c->user->emailaddress,
$c->user->emailaddress,
"New password for Hydra",
"Hi,\n\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 $ssh_key = trim $c->request->params->{"ssh_key"};
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, "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, "Invalid or empty SSH key.") if $ssh_key eq "";
$machine->update(
{ username => $username
, maxconcurrent => $maxconcurrent
@ -231,17 +231,17 @@ sub updateMachine {
if(ref($systems) eq 'ARRAY') {
for my $s (@$systems) {
$machine->buildmachinesystemtypes->create({ system => $s}) ;
}
}
} else {
$machine->buildmachinesystemtypes->create({ system => $systems}) ;
}
}
}
sub create_machine : Chained('admin') PathPart('create-machine') Args(0) {
my ($self, $c) = @_;
requireAdmin($c);
$c->stash->{template} = 'machine.tt';
$c->stash->{systemtypes} = [$c->model('DB::SystemTypes')->search({}, {order_by => "system"})];
$c->stash->{edit} = 1;
@ -253,10 +253,10 @@ sub create_machine_submit : Chained('admin') PathPart('create-machine/submit') A
my ($self, $c) = @_;
requireAdmin($c);
my $hostname = trim $c->request->params->{"hostname"};
error($c, "Invalid or empty hostname.") if $hostname eq "";
txn_do($c->model('DB')->schema, sub {
my $machine = $c->model('DB::BuildMachines')->create(
{ hostname => $hostname });
@ -272,7 +272,7 @@ sub machine_delete : Chained('machine') PathPart('delete') Args(0) {
txn_do($c->model('DB')->schema, sub {
$c->stash->{machine}->delete;
});
});
saveNixMachines($c);
$c->res->redirect("/admin/machines");
}
@ -304,7 +304,7 @@ sub clearvcscache : Chained('admin') Path('clear-vcs-cache') Args(0) {
print "Clearing path cache\n";
$c->model('DB::CachedPathInputs')->delete_all;
print "Clearing git cache\n";
$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->{template} = 'news.tt';
$c->stash->{template} = 'news.tt';
}
sub news_submit : Chained('admin') Path('news/submit') Args(0) {
my ($self, $c) = @_;
requirePost($c);
my $contents = trim $c->request->params->{"contents"};
my $createtime = time;
$c->model('DB::NewsItems')->create({
createtime => $createtime,
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.");
$newsItem->delete;
});
$c->res->redirect("/admin/news");
}
sub force_eval : Chained('admin') Path('eval') Args(2) {
my ($self, $c, $projectName, $jobsetName) = @_;
my $project = $c->model('DB::Projects')->find($projectName)
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} = $c->stash->{jobset_}->single
or notFound($c, "Jobset $jobsetName doesn't exist.");
(my $res, my $stdout, my $stderr) = captureStdoutStderr(60, ("hydra_evaluator.pl", $projectName, $jobsetName));
$c->res->redirect("/project/$projectName");
}

View file

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

View file

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