From 3c7e0ffd42a62652918f66052ff5a3e8233273d0 Mon Sep 17 00:00:00 2001 From: David Gustafsson Date: Fri, 15 Dec 2017 11:59:57 +0100 Subject: [PATCH] Bug 19819: C4::Context->dbh is unreasonably slow Locally cache Koha::Database->schema->storage->dbh in state variable in C4::Context->dbh to get rid of retrieval overhead --- C4/Context.pm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/C4/Context.pm b/C4/Context.pm index 1aa08be050..a8b073c85c 100644 --- a/C4/Context.pm +++ b/C4/Context.pm @@ -688,9 +688,13 @@ sub dbh my $self = shift; my $params = shift; my $sth; + state $dbh; unless ( $params->{new} ) { - return Koha::Database->schema->storage->dbh; + unless ($dbh) { + $dbh = Koha::Database->schema->storage->dbh; + } + return $dbh; } return Koha::Database->schema({ new => 1 })->storage->dbh; -- 2.11.0