Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
only (dis)connect once to mysql
  • Loading branch information
FROGGS committed Oct 29, 2014
1 parent 6d22454 commit 11f02bb
Showing 1 changed file with 13 additions and 25 deletions.
38 changes: 13 additions & 25 deletions app.pl
Expand Up @@ -8,13 +8,14 @@

Bailador::import;

my %db-options = :user<foo>, :password<bar>,
:host<localhost>, :port<3306>, :database<cpandatesters>;
DBIish.install_driver('mysql');
my $dbh = DBIish.connect('mysql',
:user<foo>, :password<bar>,
:host<localhost>, :port<3306>, :database<cpandatesters>
);

get '/' | '/dists' => sub {
DBIish.install_driver('mysql');
my $dbh = DBIish.connect('mysql', |%db-options);

get '/' | '/dists' => sub {
# TODO create a table `dists` and precalc its PASS ratio in a cronjob
my $sth = $dbh.prepare("SELECT DISTINCT `distname`, `distauth`
FROM `cpandatesters`.`reports`
Expand All @@ -24,20 +25,17 @@
while $sth.fetchrow_hashref -> $/ {
$dist-lines ~= template 'dist-line.tt', $/
}
$dbh.disconnect();
template 'main.tt', {
:breadcrumb(['Distributions']),
:content( template 'dists.tt', { :$dist-lines })
}
}

get /^ '/dist/' (.+) / => sub ($distname) {
DBIish.install_driver('mysql');
my $dbh = DBIish.connect('mysql', |%db-options);

my $sth = $dbh.prepare("SELECT `id`,`grade`,`distname`,`distauth`,`distver`,`compver`,`backend`,`osname`,`osver`,`arch`
FROM `cpandatesters`.`reports`
WHERE `distname`=?");
WHERE `distname`=?
ORDER BY `id` DESC");
$sth.execute($distname);
my %reports;
my @osnames = <linux mswin32 darwin netbsd openbsd freebsd solaris>;
Expand All @@ -50,7 +48,6 @@
$<breadcrumb> = "/dist/$distname";
%reports{$<distver>}.push: template 'report-line.tt', $/
}
$dbh.disconnect();
for @osnames -> $osname {
for %stats.keys -> $compver is copy {
for <moar jvm parrot> -> $backend {
Expand Down Expand Up @@ -95,9 +92,6 @@
}

get / '/report/' (.+) '/' (\d+) / => sub ($path, $id) {
DBIish.install_driver('mysql');
my $dbh = DBIish.connect('mysql', |%db-options);

my $sth = $dbh.prepare("SELECT *
FROM `cpandatesters`.`reports`
WHERE `id`=?");
Expand All @@ -108,15 +102,13 @@
if @path[0] eq 'dist' {
$breadcrumb.unshift: 'Distributions' => '/dists', @path[1] => "/dist/@path[1]"
}
$dbh.disconnect();
template 'main.tt', {
:$breadcrumb,
:content( template 'report-details.tt', $r, from-json $r<raw>)
}
}
else {
status 404;
$dbh.disconnect();
return "File not found";
}
}
Expand All @@ -130,13 +122,9 @@

post '/report' => sub {
my $report = from-json request.body;

DBIish.install_driver('mysql');
my $dbh = DBIish.connect('mysql', |%db-options);

my $sth = $dbh.prepare("INSERT INTO `cpandatesters`.`reports`
(`grade`,`distname`,`distauth`,`distver`,`compver`,`backend`,`osname`,`osver`,`arch`,`raw`)
VALUES (?,?,?,?,?,?,?,?,?,?)");
my $sth = $dbh.prepare("INSERT INTO `cpandatesters`.`reports`
(`grade`,`distname`,`distauth`,`distver`,`compver`,`backend`,`osname`,`osver`,`arch`,`raw`)
VALUES (?,?,?,?,?,?,?,?,?,?)");
$sth.execute(
$report<build-passed> && $report<test-passed> ?? 'PASS' !! 'FAIL',
$report<name>,
Expand All @@ -149,8 +137,8 @@
$report<kernel><arch>,
request.body,
);

$dbh.disconnect();
}

baile;

$dbh.disconnect();

0 comments on commit 11f02bb

Please sign in to comment.