Skip to content

Commit

Permalink
purge from cdn on favorite changes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
haarg committed Feb 14, 2024
1 parent ac05c8f commit 29164c9
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/MetaCPAN/Server/Controller/User/Favorite.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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( '/',
Expand All @@ -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) );
}
Expand Down

0 comments on commit 29164c9

Please sign in to comment.