From de7226ca2f77bf5d6fab57c61a6fdeb4fcc52c28 Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Sat, 20 Dec 2014 16:41:39 +0200 Subject: [PATCH] Purge affected pages on insert/update/delete --- Makefile.PL | 1 + lib/Gruntmaster/Data.pm | 7 ++++--- lib/Gruntmaster/Data/Result/Contest.pm | 7 +++++++ lib/Gruntmaster/Data/Result/ContestProblem.pm | 8 ++++++++ lib/Gruntmaster/Data/Result/ContestStatus.pm | 8 ++++++++ lib/Gruntmaster/Data/Result/Job.pm | 11 +++++++++++ lib/Gruntmaster/Data/Result/Open.pm | 8 ++++++++ lib/Gruntmaster/Data/Result/Problem.pm | 8 ++++++++ lib/Gruntmaster/Data/Result/ProblemStatus.pm | 8 ++++++++ lib/Gruntmaster/Data/Result/User.pm | 8 ++++++++ 10 files changed, 71 insertions(+), 3 deletions(-) diff --git a/Makefile.PL b/Makefile.PL index 6d1dc29..86e6c32 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -18,6 +18,7 @@ WriteMakefile( Authen::Passphrase 0 Authen::Passphrase::BlowfishCrypt 0 + Class::Method::Modifiers 0 Date::Parse 0 DBIx::Class 0 File::Slurp 0 diff --git a/lib/Gruntmaster/Data.pm b/lib/Gruntmaster/Data.pm index 6de2fa2..61a8f4e 100644 --- a/lib/Gruntmaster/Data.pm +++ b/lib/Gruntmaster/Data.pm @@ -17,7 +17,7 @@ __PACKAGE__->load_namespaces; use parent qw/Exporter/; our $VERSION = '5999.000_012'; -our @EXPORT = qw/purge/; +our @EXPORT = qw/purge/; ## no critic (ProhibitAutomaticExportation) use Lingua::EN::Inflect qw/PL_N/; use JSON::MaybeXS qw/decode_json/; @@ -186,8 +186,9 @@ sub update_status { 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 } - +sub purge { + $ht->request(PURGE => "http://$_$_[0]") for @PURGE_HOSTS; +} 1; diff --git a/lib/Gruntmaster/Data/Result/Contest.pm b/lib/Gruntmaster/Data/Result/Contest.pm index e7b7225..a82bc0f 100644 --- a/lib/Gruntmaster/Data/Result/Contest.pm +++ b/lib/Gruntmaster/Data/Result/Contest.pm @@ -171,8 +171,15 @@ __PACKAGE__->many_to_many("problems", "contest_problems", "problem"); # Created by DBIx::Class::Schema::Loader v0.07042 @ 2014-12-19 16:54:00 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:IxxZqQwKisBwDabCNUD55Q +use Class::Method::Modifiers qw/after/; use List::Util qw/sum/; +after qw/insert update delete/ => sub { + my ($self) = @_; + Gruntmaster::Data::purge '/ct/'; + Gruntmaster::Data::purge '/ct/' . $self->id; +}; + sub is_pending { my ($self, $time) = @_; $self->start > ($time // time) diff --git a/lib/Gruntmaster/Data/Result/ContestProblem.pm b/lib/Gruntmaster/Data/Result/ContestProblem.pm index 4ae5e4b..fd720ad 100644 --- a/lib/Gruntmaster/Data/Result/ContestProblem.pm +++ b/lib/Gruntmaster/Data/Result/ContestProblem.pm @@ -94,9 +94,17 @@ __PACKAGE__->belongs_to( # Created by DBIx::Class::Schema::Loader v0.07042 @ 2014-12-19 16:44:22 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:dTFBC3ZKB2T9SCiyQxxe2w +use Class::Method::Modifiers qw/after/; + sub rawcontest { shift->get_column('contest') } sub rawproblem { shift->get_column('problem') } +after qw/insert update delete/ => sub { + my ($self) = @_; + Gruntmaster::Data::purge '/pb/'; + Gruntmaster::Data::purge '/pb/' . $self->rawproblem; +}; + 1; __END__ diff --git a/lib/Gruntmaster/Data/Result/ContestStatus.pm b/lib/Gruntmaster/Data/Result/ContestStatus.pm index 0815e98..d4ed8fe 100644 --- a/lib/Gruntmaster/Data/Result/ContestStatus.pm +++ b/lib/Gruntmaster/Data/Result/ContestStatus.pm @@ -108,6 +108,14 @@ __PACKAGE__->belongs_to( # Created by DBIx::Class::Schema::Loader v0.07042 @ 2014-12-19 16:44:22 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:IkY4FNON0SrxrP8oNOXoHg +use Class::Method::Modifiers qw/after/; + sub rawowner { shift->get_column('owner') } +after qw/insert update delete/ => sub { + my ($self) = @_; + Gruntmaster::Data::purge '/us/'; + Gruntmaster::Data::purge '/us/' . $self->rawowner; +}; + 1; diff --git a/lib/Gruntmaster/Data/Result/Job.pm b/lib/Gruntmaster/Data/Result/Job.pm index dfb375e..39d44bd 100644 --- a/lib/Gruntmaster/Data/Result/Job.pm +++ b/lib/Gruntmaster/Data/Result/Job.pm @@ -236,6 +236,8 @@ __PACKAGE__->has_many( # Created by DBIx::Class::Schema::Loader v0.07042 @ 2014-12-19 16:54:00 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:hEAVL5heV13+nalSmgr0WA +use Class::Method::Modifiers qw/after/; + sub rawcontest { shift->get_column('contest') } sub rawowner { shift->get_column('owner') } sub rawproblem { shift->get_column('problem') } @@ -244,6 +246,15 @@ sub rerun { shift->update({daemon => undef, result => -2, result_text => undef}); } +after qw/insert update delete/ => sub { + my ($self) = @_; + Gruntmaster::Data::purge '/us/'; + Gruntmaster::Data::purge '/us/' . $self->rawowner; + Gruntmaster::Data::purge '/st/' . $self->rawcontest if $self->rawcontest; + Gruntmaster::Data::purge '/log/'; + Gruntmaster::Data::purge '/log/' . $self->id; +}; + 1; __END__ diff --git a/lib/Gruntmaster/Data/Result/Open.pm b/lib/Gruntmaster/Data/Result/Open.pm index 495df19..e5c45e2 100644 --- a/lib/Gruntmaster/Data/Result/Open.pm +++ b/lib/Gruntmaster/Data/Result/Open.pm @@ -130,9 +130,17 @@ __PACKAGE__->belongs_to( # Created by DBIx::Class::Schema::Loader v0.07042 @ 2014-12-19 16:44:22 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:jAao0vjOW87mO37ZQhm4Cw +use Class::Method::Modifiers qw/after/; + +sub rawcontest { shift->get_column('contest') } sub rawowner { shift->get_column('owner') } sub rawproblem { shift->get_column('problem') } +after qw/insert update delete/ => sub { + my ($self) = @_; + Gruntmaster::Data::purge '/st/' . $self->rawcontest; +}; + 1; __END__ diff --git a/lib/Gruntmaster/Data/Result/Problem.pm b/lib/Gruntmaster/Data/Result/Problem.pm index 34c9d87..fe5523d 100644 --- a/lib/Gruntmaster/Data/Result/Problem.pm +++ b/lib/Gruntmaster/Data/Result/Problem.pm @@ -314,6 +314,14 @@ __PACKAGE__->many_to_many("contests", "contest_problems", "contest"); # Created by DBIx::Class::Schema::Loader v0.07042 @ 2014-12-19 16:54:00 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:QZHyWOWaPmTm/EQ5M22CGA +use Class::Method::Modifiers qw/after/; + +after qw/insert update delete/ => sub { + my ($self) = @_; + Gruntmaster::Data::purge '/pb/'; + Gruntmaster::Data::purge '/pb/' . $self->id; +}; + sub is_private { my ($self, $time) = @_; return 1 if $self->private; diff --git a/lib/Gruntmaster/Data/Result/ProblemStatus.pm b/lib/Gruntmaster/Data/Result/ProblemStatus.pm index d46de2b..3b8ca4c 100644 --- a/lib/Gruntmaster/Data/Result/ProblemStatus.pm +++ b/lib/Gruntmaster/Data/Result/ProblemStatus.pm @@ -135,6 +135,14 @@ __PACKAGE__->belongs_to( # Created by DBIx::Class::Schema::Loader v0.07042 @ 2014-12-19 16:44:22 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:1OCTO6sM27DamVhQi3dWKg +use Class::Method::Modifiers qw/after/; + sub rawowner { shift->get_column('owner') } +after qw/insert update delete/ => sub { + my ($self) = @_; + Gruntmaster::Data::purge '/us/'; + Gruntmaster::Data::purge '/us/' . $self->rawowner; +}; + 1; diff --git a/lib/Gruntmaster/Data/Result/User.pm b/lib/Gruntmaster/Data/Result/User.pm index 0b0ba4b..73fe6ab 100644 --- a/lib/Gruntmaster/Data/Result/User.pm +++ b/lib/Gruntmaster/Data/Result/User.pm @@ -215,6 +215,14 @@ __PACKAGE__->has_many( # Created by DBIx::Class::Schema::Loader v0.07042 @ 2014-12-19 16:54:00 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:LiA2+ZpTTelwZJtFpZRsbw +use Class::Method::Modifiers qw/after/; + +after qw/insert update delete/ => sub { + my ($self) = @_; + Gruntmaster::Data::purge '/us/'; + Gruntmaster::Data::purge '/us/' . $self->id; +}; + use Authen::Passphrase; use Authen::Passphrase::BlowfishCrypt; -- 2.39.2