From: Robert Buels Date: Mon, 10 Aug 2009 18:45:50 +0000 (+0000) Subject: added caching of pg search path in Pg storage object X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1ff9c30db9648d11f9ae1795cf2f2d20895253a3;p=dbsrgits%2FDBIx-Class-Historic.git added caching of pg search path in Pg storage object --- diff --git a/lib/DBIx/Class/Storage/DBI/Pg.pm b/lib/DBIx/Class/Storage/DBI/Pg.pm index 2e516fd..baf30fb 100644 --- a/lib/DBIx/Class/Storage/DBI/Pg.pm +++ b/lib/DBIx/Class/Storage/DBI/Pg.pm @@ -33,6 +33,23 @@ sub last_insert_id { $self->dbh_do('_dbh_last_insert_id', $seq); } +sub _get_pg_search_path { + my ($self,$dbh) = @_; + # cache the search path as ['schema','schema',...] in the storage + # obj + $self->{_pg_search_path} ||= do { + my @search_path; + my ($sp_string) = $dbh->selectrow_array('SHOW search_path'); + while( $sp_string =~ s/("[^"]+"|[^,]+),?// ) { + unless( defined $1 and length $1 ) { + $self->throw_exception("search path sanity check failed: '$1'") + } + push @search_path, $1; + } + \@search_path + }; +} + sub _dbh_get_autoinc_seq { my ($self, $dbh, $schema, $table, @pri) = @_; @@ -42,13 +59,7 @@ sub _dbh_get_autoinc_seq { if( defined $schema and length $schema ) { @search_path = ( $schema ); } else { - my ($search_path) = $dbh->selectrow_array('SHOW search_path'); - while( $search_path =~ s/("[^"]+"|[^,]+),?// ) { - unless( defined $1 and length $1 ) { - $self->throw_exception("search path sanity check failed: '$1'") - } - push @search_path, $1; - } + @search_path = @{ $self->_get_pg_search_path($dbh) }; } foreach my $search_schema (@search_path) {