@@ -, +, @@ 1) The loading of the schemas themselves, which is done upon import of Koha::Database. This requires moving the import of Koha::Schema from an on-demand `require` to just a `use`; most everything in Koha uses C4::Context, which will indirectly end up calling Koha::Database->schema->new anyway, so this was no longer saving anything. 2) The actual database connection, which is done by cloning the schema created above and adding a database connection. * First load of koha2marclinks.pl on a new worker: 0.70 seconds * Each load after: 0.17 seconds * First load: 0.31 seconds * Each load after: 0.17 seconds --- Koha/Database.pm | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) --- a/Koha/Database.pm +++ a/Koha/Database.pm @@ -35,20 +35,23 @@ Koha::Database use Modern::Perl; use Carp; use C4::Context; +use Koha::Schema; use base qw(Class::Accessor); use vars qw($database); __PACKAGE__->mk_accessors(qw( )); +BEGIN { + # Initialize the base schema object (just loads the schema classes) + $database->{base_schema} = Koha::Schema->clone; +} + # _new_schema # Internal helper function (not a method!). This creates a new # database connection from the data given in the current context, and # returns it. sub _new_schema { - - require Koha::Schema; - my $context = C4::Context->new(); my $db_driver = $context->{db_driver}; @@ -70,7 +73,10 @@ sub _new_schema { $encoding_query = "set client_encoding = 'UTF8';"; $tz_query = qq(SET TIME ZONE = "$tz") if $tz; } - my $schema = Koha::Schema->connect( + + # This creates a new copy of the schema with its own database handle but with all the schema + # classes already loaded. + my $schema = $database->{base_schema}->connect( { dsn => "dbi:$db_driver:database=$db_name;host=$db_host;port=$db_port", user => $db_user, --