From Redis to Postgres - Part 3 (Bugfixes, first try)
authorMarius Gavrilescu <marius@ieval.ro>
Wed, 19 Mar 2014 16:28:52 +0000 (18:28 +0200)
committerMarius Gavrilescu <marius@ieval.ro>
Wed, 19 Mar 2014 16:29:14 +0000 (18:29 +0200)
app.psgi
lib/Gruntmaster/Page/Generic.pm
lib/Gruntmaster/Page/Src.pm
lib/Gruntmaster/Page/St.pm
lib/Plack/App/Gruntmaster.pm

index 2e3f6405c7b7848c5ee1e8ffde433430f92e2260..e662e264184bbf6c93705e9105895590e38014f0 100644 (file)
--- a/app.psgi
+++ b/app.psgi
@@ -61,6 +61,7 @@ sub mangle_request {
                        $env->{'gruntmaster.problem'} = $1 if s,^/pb/$word/,/,;
                        $env->{'gruntmaster.contest'} = $1 if s,^/ct/$word/,/,;
                        $env->{'gruntmaster.user'}    = $1 if s,^/us/$word/,/,;
+                       $env->{'gruntmaster.page'}  //= -1 if m,^/log/$,;
                }
                $app->($env);
        }
index 256add635bed2a31ed85d929cab7e710722ea57f..10ed5568e6831b88ea43d0da93b27956dab7016c 100644 (file)
@@ -37,6 +37,7 @@ sub list {
        $rs = $rs->search(undef, {order_by => 'me.id'}) unless $rs->is_ordered;
        if (my $page = $env->{'gruntmaster.page'}) {
                my $pages = $rs->count / PAGE_SIZE;
+               $page = $pages if $page == -1;
                $rs = $rs->search(undef, {offset => ($page - 1) * PAGE_SIZE, ($page == $pages ? () : (rows => PAGE_SIZE))});
        }
        $rs = $rs->search(undef, {prefetch => $thing{prefetch}}) if exists $thing{prefetch};
index e54e79f9840508f0cb696de534054fd765db511c..4fc2550dc9b2d9c0fcc2889a9331409e74d78301 100644 (file)
@@ -13,8 +13,8 @@ use constant CONTENT_TYPES => +{
 };
 
 sub generate{
-       my ($self, $format, $env, $ct, $job, $ext) = @_;
-       debug $env => "Contest is $ct, job is $job and extension is $ext";
+       my ($self, $format, $env, $job, $ext) = @_;
+       debug $env => "Job is $job and extension is $ext";
 
        [200, ['Content-Type' => CONTENT_TYPES->{$ext}, 'Cache-Control' => 'max-age=604800', 'X-Forever' => 1], [db($env)->job($job)->source] ]
 }
index 2d7b23831f29cb08420ae5d04f90dc1b9d07279c..547eaba544297c8ea7d49947558e9c90ee8a2b5d 100644 (file)
@@ -21,14 +21,14 @@ sub calc_score{
 }
 
 sub _generate{
-       my ($self, $htc, $lang, $env, $ct) = @_;
-       debug $env => "language is '$lang' and contest is '$ct'";
+       my ($self, $htc, $lang, $env) = @_;
+       #debug $env => "language is '$lang'";
 
-       $ct &&= db($env)->contest($ct);
+       my $ct = $env->{'gruntmaster.contest'} && db($env)->contest($env->{'gruntmaster.contest'});
 
-       my @problems = map { $_->problem } db($env)->contest_problems->search({contest => $ct->id}, {qw/join problem order_by problem.level/});
+       my @problems = map { $_->problem } db($env)->contest_problems->search({contest => $ct && $ct->id}, {qw/join problem order_by problem.level/});
        my (%scores, %tries);
-       for my $job (db($env)->jobs->search({contest => $ct->id})) {
+       for my $job (db($env)->jobs->search({contest => $ct && $ct->id})) {
 
                if ($ct) {
                        my $time = $job->date - $ct->start;
@@ -42,7 +42,7 @@ sub _generate{
                }
        }
 
-       my @st = sort { $b->{score} <=> $a->{score} or $a->{user} cmp $b->{user}} map {
+       my @st = sort { $b->{score} <=> $a->{score} or $a->{user}->id cmp $b->{user}->id} map {
                my $user = $_;
                +{
                        user => db($env)->user($user),
index 5b5f6606a25507f9f105faaff4586895ce48e335..8d828c0963d27de49f6f9fd05a6e884dfd9eb013 100644 (file)
@@ -75,9 +75,9 @@ BEGIN{
        get qr,/css/$word\.css, => 'CSS';
        get qr,/js\.js, => 'JS';
 
+       get qr,/log/st, => 'St';
        generic qw/us ct pb log/;
 
-       get qr,/log/st, => 'St';
        get qr,/log/src/$number\.$word, => 'Src';
        post qr,/pb/$word/submit, => 'Submit';
 
This page took 0.015125 seconds and 4 git commands to generate.