+sub update_status {
+ my ($self) = @_;
+ my @jobs = $self->jobs->search(undef, {cache => 1})->all;
+
+ my %hash;
+ $hash{$_->get_column('problem'), $_->get_column('owner')} = [$_->id, $_->result ? 0 : 1] for @jobs;
+ my @problem_statuses = map { [split ($;), @{$hash{$_}} ] } keys %hash;
+
+ my @contest_statuses = map {
+ my $contest = $_->id;
+ map { [$contest, $_->{user}, $_->{score}, $_->{rank}] } $_->standings
+ } $self->contests->all;
+
+ my $txn = sub {
+ $self->problem_statuses->delete;
+ $self->problem_statuses->populate([[qw/problem owner job solved/], @problem_statuses]);
+ $self->contest_statuses->delete;
+ $self->contest_statuses->populate([[qw/contest owner score rank/], @contest_statuses]);
+ };
+
+ $self->txn_do($txn);
+}
+
+my @PURGE_HOSTS = exists $ENV{PURGE_HOSTS} ? split ' ', $ENV{PURGE_HOSTS} : ();
+my $ht = HTTP::Tiny->new;
+
+sub purge {
+ $ht->request(PURGE => "http://$_$_[0]") for @PURGE_HOSTS;
+}
+