From 281c39520901fe9bd4b4f7de001c444d1ddf25e5 Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Fri, 12 Dec 2014 15:17:37 +0200 Subject: [PATCH] Include problem/contest counts in user_list --- lib/Gruntmaster/Data.pm | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/Gruntmaster/Data.pm b/lib/Gruntmaster/Data.pm index 0b04b7b..e8b5c73 100644 --- a/lib/Gruntmaster/Data.pm +++ b/lib/Gruntmaster/Data.pm @@ -42,8 +42,13 @@ BEGIN { } sub user_list { - my $rs = $_[0]->users->search(undef, {order_by => 'name', columns => USER_PUBLIC_COLUMNS}); - [ map { { $_->get_columns } } $rs->all ] + my $rs = $_[0]->users->search(undef, {columns => USER_PUBLIC_COLUMNS, prefetch => [qw/problem_statuses contest_statuses/]} ); + [ sort { $b->{solved} <=> $a->{solved} or $b->{attempted} <=> $a->{attempted} }map { + my $solved = $_->problem_statuses->count(solved => 1); + my $attempted = $_->problem_statuses->count(solved => 0); + my $contests = $_->contest_statuses->count; + +{ $_->get_columns, solved => $solved, attempted => $attempted, contests => $contests } + } $rs->all ] } sub user_entry { -- 2.39.2