From 920cc99c0d976e42bd6b57d0cc66e6a06ab352c4 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 20 Jan 2025 10:27:33 -0300 Subject: [PATCH] Bug 38927: Only call FindDuplicate if required This patch makes the code call `FindDuplicate` only if `x-confirm-not-duplicate` is not passed. This makes sense, as having it passed makes it override any duplicate found. This patch doesn't change any end user behavior, just makes the code more efficient. To test: 1. Run: $ ktd --shell k$ prove t/db_dependent/api/v1/biblios.t => SUCCESS: Tests pass 2. Apply this patch 3. Repeat 1 => SUCCESS: Tests pass, no behavior change 4. Sign off :-D Signed-off-by: Jonathan Druart Signed-off-by: Paul Derscheid --- Koha/REST/V1/Biblios.pm | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/Koha/REST/V1/Biblios.pm b/Koha/REST/V1/Biblios.pm index 035d215c52..0b5db5dc9a 100644 --- a/Koha/REST/V1/Biblios.pm +++ b/Koha/REST/V1/Biblios.pm @@ -691,17 +691,18 @@ sub add { ); } - my ( $duplicatebiblionumber, $duplicatetitle ); - ( $duplicatebiblionumber, $duplicatetitle ) = FindDuplicate($record); - my $confirm_not_duplicate = $headers->header('x-confirm-not-duplicate'); - return $c->render( - status => 400, - openapi => { - error => "Duplicate biblio $duplicatebiblionumber", - } - ) unless !$duplicatebiblionumber || $confirm_not_duplicate; + if ( !$confirm_not_duplicate ) { + my ( $duplicatebiblionumber, $duplicatetitle ) = FindDuplicate($record); + + return $c->render( + status => 400, + openapi => { + error => "Duplicate biblio $duplicatebiblionumber", + } + ) if $duplicatebiblionumber; + } my ( $biblio_id ) = AddBiblio( $record, $frameworkcode, { record_source_id => $record_source_id } ); -- 2.39.5