From 1ed05f85a03e43d87a7b1a4603b252ed7b3a769e Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 22 Feb 2021 09:27:12 -0300 Subject: [PATCH] Bug 27071: (follow-up) Get rid of loop This patch gets rid of a loop on the librarary's groups siblings, and acknowledges ->get_hold_libraries returns a proper Koha::Libraries iterator that can be chained with a new query on the passed branchcode. This way we only fetch a count from the DB and no loop needs to take place on the code. To test: 1. Apply this patch 2. Run: $ kshell k$ prove t/db_dependent/Koha/Libraries.t => SUCCESS: Tests pass! 3. Sign off :-D Signed-off-by: Tomas Cohen Arazi Signed-off-by: David Nind Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart (cherry picked from commit 3495a7e9af70706e3ebba60e3fac7aa3845d1d78) Signed-off-by: Fridolin Somers (cherry picked from commit 3525fc03c6d6bb7dbb3e0d49ac8e68444839e82b) Signed-off-by: Andrew Fuerste-Henry --- Koha/Library.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Koha/Library.pm b/Koha/Library.pm index 32e7d0f46b..13f8c1f9a5 100644 --- a/Koha/Library.pm +++ b/Koha/Library.pm @@ -175,8 +175,8 @@ sub validate_hold_sibling { return 1 if $params->{branchcode} eq $self->id; my $branchcode = $params->{branchcode}; - my @hold_libraries = $self->get_hold_libraries; - return grep {$_->branchcode eq $branchcode} @hold_libraries; + return $self->get_hold_libraries->search( { branchcode => $branchcode } ) + ->count > 0; } =head2 Internal methods -- 2.39.5