From 29164c99b8cb7579506b759c9f73724a535049b0 Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Wed, 14 Feb 2024 10:57:41 +0100 Subject: [PATCH] purge from cdn on favorite changes We should be purging the relevant tags when favorites are added or removed. Currently, the front end does this, but it really should be handled by the API server. --- lib/MetaCPAN/Server/Controller/User/Favorite.pm | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/MetaCPAN/Server/Controller/User/Favorite.pm b/lib/MetaCPAN/Server/Controller/User/Favorite.pm index f88f50dc5..619864b49 100644 --- a/lib/MetaCPAN/Server/Controller/User/Favorite.pm +++ b/lib/MetaCPAN/Server/Controller/User/Favorite.pm @@ -25,17 +25,18 @@ sub index : Path : ActionClass('REST') { sub index_POST { my ( $self, $c ) = @_; my $pause = $c->stash->{pause}; - my $req = $c->req; + my $data = $c->req->data; my $favorite = $c->model('CPAN::Favorite')->put( { user => $c->user->id, - author => $req->data->{author}, - release => $req->data->{release}, - distribution => $req->data->{distribution}, - author => $req->data->{author}, + author => $data->{author}, + release => $data->{release}, + distribution => $data->{distribution}, }, { refresh => 1 } ); + $c->purge_author_key( $data->{author} ) if $data->{author}; + $c->purge_dist_key( $data->{distribution} ) if $data->{distribution}; $self->status_created( $c, location => $c->uri_for( join( '/', @@ -50,6 +51,9 @@ sub index_DELETE { ->get( { user => $c->user->id, distribution => $distribution } ); if ($favorite) { $favorite->delete( { refresh => 1 } ); + $c->purge_author_key( $favorite->author ) + if $favorite->author; + $c->purge_dist_key($distribution); $self->status_ok( $c, entity => $favorite->meta->get_data($favorite) ); }