From: Dagfinn Ilmari Mannsåker Date: Sat, 29 Aug 2015 22:34:50 +0000 (+0100) Subject: Cache the result of _tables_list X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=08886922039afb28ccc7a47a9d79eb2eb042f2d8;p=dbsrgits%2FDBIx-Class-Schema-Loader.git Cache the result of _tables_list --- diff --git a/Changes b/Changes index d71d1e0..f93c43e 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,7 @@ Revision history for Perl extension DBIx::Class::Schema::Loader - Fix Pg date/time types with zero fractional second digits + - Reduce the number of queries by caching the list of tables 0.07043 2015-05-13 - Fix many_to_many bridges with overlapping foreign keys diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index 3b14622..38f5291 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -1623,7 +1623,7 @@ Does the actual schema-construction work. sub load { my $self = shift; - $self->_load_tables($self->_tables_list); + $self->_load_tables($self->__tables_list); } =head2 rescan @@ -1643,9 +1643,10 @@ sub rescan { $self->{schema} = $schema; $self->_relbuilder->{schema} = $schema; + $self->{_cache} = {}; my @created; - my @current = $self->_tables_list; + my @current = $self->__tables_list; foreach my $table (@current) { if(!exists $self->_tables->{$table->sql_name}) { @@ -2877,6 +2878,11 @@ sub _table_fk_info { croak "ABSTRACT METHOD" } # Returns an array of lower case table names sub _tables_list { croak "ABSTRACT METHOD" } +sub __tables_list { + my ($self) = @_; + return @{$self->{_cache}{_tables_list} ||= [ $self->_tables_list ]}; +} + # Execute a constructive DBIC class method, with debug/dump_to_dir hooks. sub _dbic_stmt { my $self = shift; diff --git a/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm b/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm index 79e345e..b9a22ff 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm @@ -107,7 +107,7 @@ sub _table_fk_info { first { lc($_->name) eq lc($f_table) && ((not $f_schema) || lc($_->schema) eq lc($f_schema)) - } $self->_tables_list; + } $self->__tables_list; }; # The table may not be in any database, or it may not have been found by the previous code block for whatever reason.