Bug 39322: (follow-up) Further improvements
This patch updates the query logic of create_from_statistic for borrower attributes. We replace the count of attributes types with a query to fetch all attributes type codes where keep_for_pseudonymization is set. We then check for content in that array before using it to perform a filtered search on the patrons extended_attributes to only return attributes set for pseudonymization. This should result in the same skip of extended_attributes fetch should no attribute types be set to pseudonymization, but it should also reduce the 1 call to attribute types per attribute the patron has to just a single filtered call for patron attributes attributes followed by the store call for each pseudonymizated attribute. Test plan: As before, except there should be even fewer sql calls to the database than before for the case where there are attributes. Signed-off-by: Nick Clemens <nick@bywatersolutions.com> Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
parent
10b84d9df4
commit
64b4e7cc27
|
|
@ -98,15 +98,22 @@ sub create_from_statistic {
|
|||
|
||||
$self->store();
|
||||
|
||||
if ( $patron && Koha::Patron::Attribute::Types->search( { keep_for_pseudonymization => 1 } )->count > 0 ) {
|
||||
my $extended_attributes = $patron->extended_attributes->unblessed;
|
||||
for my $attribute (@$extended_attributes) {
|
||||
next unless Koha::Patron::Attribute::Types->find( $attribute->{code} )->keep_for_pseudonymization;
|
||||
if ($patron) {
|
||||
my @kept_types = Koha::Patron::Attribute::Types->search(
|
||||
{ keep_for_pseudonymization => 1 },
|
||||
{ columns => ['code'] }
|
||||
)->get_column('code');
|
||||
|
||||
delete $attribute->{id};
|
||||
delete $attribute->{borrowernumber};
|
||||
if (@kept_types) {
|
||||
my $extended_attributes =
|
||||
$patron->extended_attributes->search( { code => { -in => \@kept_types } } )->unblessed;
|
||||
|
||||
$self->_result->create_related( 'pseudonymized_borrower_attributes', $attribute );
|
||||
for my $attribute (@$extended_attributes) {
|
||||
delete $attribute->{id};
|
||||
delete $attribute->{borrowernumber};
|
||||
|
||||
$self->_result->create_related( 'pseudonymized_borrower_attributes', $attribute );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue