From 1b0c2a9436d31c382298809801b7048ff4bce9b3 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 9 Nov 2017 10:34:08 -0300 Subject: [PATCH] Bug 19599: Execute 1 query per patron --- Koha/Patron.pm | 12 +++++++++--- Koha/Patrons.pm | 13 ++++++++----- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 92e70a5b91..c13706d659 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -512,14 +512,20 @@ sub add_enrolment_fee_if_needed { =head3 checkouts -my $issues = $patron->checkouts +my $checkouts = $patron->checkouts =cut sub checkouts { my ($self) = @_; - my $issues = $self->_result->issues; - return Koha::Checkouts->_new_from_dbic( $issues ); + my $checkouts = $self->_result->issues; + return Koha::Checkouts->_new_from_dbic( $checkouts ); +} + +sub old_checkouts { + my ($self) = @_; + my $old_checkouts = $self->_result->old_issues; + return Koha::Old::Checkouts->_new_from_dbic( $old_checkouts ); } =head3 get_overdues diff --git a/Koha/Patrons.pm b/Koha/Patrons.pm index 263cec72a4..fd2b997583 100644 --- a/Koha/Patrons.pm +++ b/Koha/Patrons.pm @@ -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 -- 2.11.0