From: Marius Gavrilescu Date: Wed, 19 Mar 2014 16:28:52 +0000 (+0200) Subject: From Redis to Postgres - Part 3 (Bugfixes, first try) X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=dfc0018254d6a5e5aed4986ae317cff6a5a89b78;p=plack-app-gruntmaster.git From Redis to Postgres - Part 3 (Bugfixes, first try) --- diff --git a/app.psgi b/app.psgi index 2e3f640..e662e26 100644 --- 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); } diff --git a/lib/Gruntmaster/Page/Generic.pm b/lib/Gruntmaster/Page/Generic.pm index 256add6..10ed556 100644 --- a/lib/Gruntmaster/Page/Generic.pm +++ b/lib/Gruntmaster/Page/Generic.pm @@ -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}; diff --git a/lib/Gruntmaster/Page/Src.pm b/lib/Gruntmaster/Page/Src.pm index e54e79f..4fc2550 100644 --- a/lib/Gruntmaster/Page/Src.pm +++ b/lib/Gruntmaster/Page/Src.pm @@ -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] ] } diff --git a/lib/Gruntmaster/Page/St.pm b/lib/Gruntmaster/Page/St.pm index 2d7b238..547eaba 100644 --- a/lib/Gruntmaster/Page/St.pm +++ b/lib/Gruntmaster/Page/St.pm @@ -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), diff --git a/lib/Plack/App/Gruntmaster.pm b/lib/Plack/App/Gruntmaster.pm index 5b5f660..8d828c0 100644 --- a/lib/Plack/App/Gruntmaster.pm +++ b/lib/Plack/App/Gruntmaster.pm @@ -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';