sub purge;
-sub query {
+sub _query {
my ($stat, @extra) = @_;
$db->query($statements{$stat}, @extra)
}
my (%name_cache, %name_cache_time);
use constant NAME_CACHE_MAX_AGE => 5;
-sub object_name {
+sub _object_name {
my ($table, $id) = @_;
$name_cache_time{$table} //= 0;
if (time - $name_cache_time{$table} > NAME_CACHE_MAX_AGE) {
}
-sub add_names ($) { ## no critic (ProhibitSubroutinePrototypes)
+sub _add_names ($) { ## no critic (ProhibitSubroutinePrototypes)
my ($el) = @_;
return unless defined $el;
if (ref $el eq 'ARRAY') {
- &add_names ($_) for @$el ## no critic (ProhibitAmpersandSigils)
+ &_add_names ($_) for @$el ## no critic (ProhibitAmpersandSigils)
} else {
for my $object (qw/contest owner problem/) {
my $table = $object eq 'owner' ? 'users' : "${object}s";
- $el->{"${object}_name"} = object_name $table, $el->{$object} if defined $el->{$object}
+ $el->{"${object}_name"} = _object_name $table, $el->{$object} if defined $el->{$object}
}
}
$el
}
-sub user_list { scalar query('user_list_sth')->hashes }
+sub user_list { scalar _query('user_list_sth')->hashes }
sub user_entry {
my ($id) = @_;
- my $ret = query('user_entry_sth', $id)->hash;
- $ret->{problems} = add_names query('problem_status_sth', $id)->hashes;
- $ret->{contests} = add_names query('contest_status_sth', $id)->hashes;
+ my $ret = _query('user_entry_sth', $id)->hash;
+ $ret->{problems} = _add_names _query('problem_status_sth', $id)->hashes;
+ $ret->{contests} = _add_names _query('contest_status_sth', $id)->hashes;
$ret;
}
$where{owner} = $args{owner} if $args{owner};
my $table = $args{contest} ? 'problems JOIN contest_problems cp ON cp.problem = id' : 'problems';
- add_names $db->select(\$table, \@columns, \%where, 'name')->hashes
+ _add_names $db->select(\$table, \@columns, \%where, 'name')->hashes
}
sub problem_entry {
my ($id, $contest) = @_;
$contest = contest_entry ($contest) if $contest;
- my $ret = add_names query(problem_entry_sth => $id)->hash;
- my $limits = query(limits_sth => $id)->hashes;
+ my $ret = _add_names _query(problem_entry_sth => $id)->hash;
+ my $limits = _query(limits_sth => $id)->hashes;
$ret->{limits} = $limits if @$limits;
if ($contest) {
$ret
}
-sub contest_list { add_names query('contest_list_sth')->hashes }
+sub contest_list { _add_names _query('contest_list_sth')->hashes }
-sub contest_entry { add_names query(contest_entry_sth => $_[0])->hash }
+sub contest_entry { _add_names _query(contest_entry_sth => $_[0])->hash }
-sub contest_has_problem { query('contest_has_problem_sth', @_[0, 1])->flat }
+sub contest_has_problem { _query('contest_has_problem_sth', @_[0, 1])->flat }
sub job_list {
my (%args) = @_;
my $rows = $db->select('job_entry', 'COUNT(*)', \%where)->list;
my $pages = int (($rows + JOBS_PER_PAGE - 1) / JOBS_PER_PAGE);
my ($stmt, @bind) = $db->abstract->select('job_entry', '*', \%where, {-desc => 'id'});
- my $jobs = add_names $db->query("$stmt LIMIT " . JOBS_PER_PAGE . ' OFFSET ' . ($args{page} - 1) * JOBS_PER_PAGE, @bind)->hashes;
+ my $jobs = _add_names $db->query("$stmt LIMIT " . JOBS_PER_PAGE . ' OFFSET ' . ($args{page} - 1) * JOBS_PER_PAGE, @bind)->hashes;
my $pageinfo = {
current_page => $args{page},
last_page => $pages,
}
sub job_entry {
- my $ret = add_names query(job_entry_sth => $_[0])->hash;
+ my $ret = _add_names _query(job_entry_sth => $_[0])->hash;
$ret->{results} = decode_json $ret->{results} if $ret->{results};
$ret
}
$ct = contest_entry $ct;
my (%scores, %tries, %opens);
- my $opens = query(opens_sth => $ct->{id});
+ my $opens = _query(opens_sth => $ct->{id});
while ($opens->into(my ($problem, $owner, $time))) {
$opens{$problem, $owner} = $time;
}
my $user = $_;
+{
user => $user,
- user_name => object_name(users => $user),
+ user_name => _object_name(users => $user),
score => sum (values %{$scores{$user}}),
scores => [map { $scores{$user}{$_->{id}} // '-'} @problems],
}
sub rerun_job {
my ($id) = @_;
- query rerun_job_sth => $id;
+ _query rerun_job_sth => $id;
purge '/log/';
purge "/log/$id";
}
sub take_job {
my ($daemon) = @_;
- my $id = query(take_job_sth => $daemon)->list;
+ my $id = _query(take_job_sth => $daemon)->list;
return $id ? db->select(jobs => '*', {id => $id})->hash : undef;
}