From f92af596c1fd092b314eae65402e96d34e4bd03a 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 --- 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 010f96e7e96..794a968af83 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) = C4::Biblio::AddBiblio( $record, $frameworkcode, { record_source_id => $record_source_id } ); -- 2.48.1