From eb04d174d91201b05b6e348dc672f9351dc0aaf0 Mon Sep 17 00:00:00 2001 From: Jacek Ablewicz Date: Wed, 30 Mar 2016 12:21:03 +0200 Subject: [PATCH] Bug 16168: Eliminate unneeded C4::Context->dbh calls in C4/Biblio.pm Right now, ->dbh calls are actually quite expensive (they involve DB connection health checks, each and every time). Some speed-sensitive subroutines inside C4/Biblio.pm (GetMarcStructure, GetAuthorisedValueDesc) have this statement my $dbh = C4::Context->dbh; on top of the code, but they don't always/don't usually need DB handle - not at that stage at least. This trivial patch eliminates unneeded ->dbh calls in those subroutines. With it, average GetMarcStructure() running time goes down from 14 miliseconds to 9 miliseconds (on top of Bug 16166), it also makes catalogue search profiling a bit easier. Test plan: 1) apply patch 2) ensure that catalogue searches are still working 3) run t/*Biblio* tests Signed-off-by: Jonathan Druart Signed-off-by: Katrin Fischer Signed-off-by: Brendan Gallagher brendan@bywatersolutions.com --- C4/Biblio.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 188870c74c..75afaa1d34 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -1114,7 +1114,6 @@ $frameworkcode : the framework code to read sub GetMarcStructure { my ( $forlibrarian, $frameworkcode ) = @_; - my $dbh = C4::Context->dbh; $frameworkcode = "" unless $frameworkcode; $forlibrarian = $forlibrarian ? 1 : 0; @@ -1123,6 +1122,7 @@ sub GetMarcStructure { my $cached = $cache->get_from_cache($cache_key); return $cached if $cached; + my $dbh = C4::Context->dbh; my $sth = $dbh->prepare( "SELECT tagfield,liblibrarian,libopac,mandatory,repeatable FROM marc_tag_structure @@ -1667,7 +1667,6 @@ descriptions rather than normal ones when they exist. sub GetAuthorisedValueDesc { my ( $tag, $subfield, $value, $framework, $tagslib, $category, $opac ) = @_; - my $dbh = C4::Context->dbh; if ( !$category ) { @@ -1687,6 +1686,7 @@ sub GetAuthorisedValueDesc { $category = $tagslib->{$tag}->{$subfield}->{'authorised_value'}; } + my $dbh = C4::Context->dbh; if ( $category ne "" ) { my $sth = $dbh->prepare( "SELECT lib, lib_opac FROM authorised_values WHERE category = ? AND authorised_value = ?" ); $sth->execute( $category, $value ); @@ -2618,6 +2618,7 @@ hash_ref sub TransformMarcToKoha { my ( $dbh, $record, $frameworkcode, $limit_table ) = @_; + ## FIXME: $dbh parameter is never used inside this subroutine ??? my $result = {}; if (!defined $record) { -- 2.39.5