From: Michael G Schwern Date: Sat, 15 Mar 2008 05:01:47 +0000 (+0000) Subject: Reduce the number of times $self->_dbh is called inside dbh_do() to speed X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6ad1059d09a2a4ccb707b06d1252d39318a7d9cc;p=dbsrgits%2FDBIx-Class-Historic.git Reduce the number of times $self->_dbh is called inside dbh_do() to speed up that hot bit of code. --- diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 1517b4a..d39ec5d 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -577,7 +577,9 @@ sub dbh_do { my $self = shift; my $code = shift; - return $self->$code($self->_dbh, @_) if $self->{_in_dbh_do} + my $dbh = $self->_dbh; + + return $self->$code($dbh, @_) if $self->{_in_dbh_do} || $self->{transaction_depth}; local $self->{_in_dbh_do} = 1; @@ -586,16 +588,20 @@ sub dbh_do { my $want_array = wantarray; eval { - $self->_verify_pid if $self->_dbh; - $self->_populate_dbh if !$self->_dbh; + $self->_verify_pid if $dbh; + if( !$dbh ) { + $self->_populate_dbh; + $dbh = $self->_dbh; + } + if($want_array) { - @result = $self->$code($self->_dbh, @_); + @result = $self->$code($dbh, @_); } elsif(defined $want_array) { - $result[0] = $self->$code($self->_dbh, @_); + $result[0] = $self->$code($dbh, @_); } else { - $self->$code($self->_dbh, @_); + $self->$code($dbh, @_); } };