Skip to content

Commit

Permalink
Clean the person lookup cache after deleting
Browse files Browse the repository at this point in the history
  • Loading branch information
jrouzierinverse committed Dec 30, 2024
1 parent 8f5d110 commit 36a60a2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
13 changes: 13 additions & 0 deletions lib/pf/UnifiedApi/Controller/Users.pm
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ use pf::security_event;
use pf::constants;
use pf::person qw(person_security_events person_unassign_nodes person_delete person_modify);
use pf::node;
use pf::lookup::person;
use pf::constants qw($default_pid);
use pf::constants::realm;
use pf::error qw(is_error is_success);
use pf::UnifiedApi::Search::Builder::Users;
use pf::lookup::person qw();

has 'search_builder_class' => 'pf::UnifiedApi::Search::Builder::Users';

Expand Down Expand Up @@ -658,6 +661,16 @@ sub _can_remove {
}
}

sub post_delete {
my ($self) = @_;
my $item = $self->item;
my $source = $item->{source};
for my $ctx ('', @pf::constants::realm::CONTEXTS) {
pf::lookup::person::clear_lookup_person($self->id, $item->{source}, $ctx);
}

}

=head1 AUTHOR
Inverse inc. <[email protected]>
Expand Down
10 changes: 9 additions & 1 deletion lib/pf/lookup/person.pm
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use pf::authentication;
use pf::pfqueue::producer::redis;
use pf::CHI;

my $CHI_CACHE = pf::CHI->new( namespace => 'person_lookup' );
our $CHI_CACHE = pf::CHI->new( namespace => 'person_lookup' );

=head2 lookup_person
Expand Down Expand Up @@ -91,6 +91,14 @@ sub async_lookup_person {
$client->submit("general", person_lookup => {pid => $pid, source_id => $source_id, context => $context});
}

sub clear_lookup_person {
my ($pid, $source_id, $context) = @_;
my $logger = get_logger();
my $cache_key = "$source_id.$pid.$context";
$CHI_CACHE->remove($cache_key);
$logger->info("Clear cache for pid $pid with key $cache_key");
}

=head1 AUTHOR
Inverse inc. <[email protected]>
Expand Down

0 comments on commit 36a60a2

Please sign in to comment.