Bug 19599: Speed anonymise_issue_history up

The query generated by anonymise_issue_history is unecessary complex and
can be very slow on large DB.
With this patch we will execute one query per patron instead.

See patch "Bug 19599: Simplify the query" on the bug report for an
alternative.

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Jonathan Druart 2017-11-09 10:34:08 -03:00
parent cf57457d34
commit 9aa724cdf2
1 changed files with 8 additions and 5 deletions

View File

@ -168,8 +168,9 @@ sub anonymise_issue_history {
# The anonymisation should not fail quietly if AnonymousPatron is not a valid entry
# Set it to undef (NULL)
my $dtf = Koha::Database->new->schema->storage->datetime_parser;
my $old_issues_to_anonymise = $self->search_related(
'old_issues',
my $nb_rows = 0;
while ( my $patron = $self->next ) {
my $old_issues_to_anonymise = $patron->old_checkouts->search(
{
(
$older_than_date
@ -178,9 +179,11 @@ sub anonymise_issue_history {
: ()
)
}
);
my $anonymous_patron = C4::Context->preference('AnonymousPatron') || undef;
$old_issues_to_anonymise->update( { 'old_issues.borrowernumber' => $anonymous_patron } );
);
my $anonymous_patron = C4::Context->preference('AnonymousPatron') || undef;
$nb_rows += $old_issues_to_anonymise->update( { 'old_issues.borrowernumber' => $anonymous_patron } );
}
return $nb_rows;
}
=head3 type