From 231c9d106cb7a7c8f39690522dd8f2257c69e3fc 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 Signed-off-by: Josef Moravec --- C4/Context.pm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/C4/Context.pm b/C4/Context.pm index 1eb5f88..79dd36f 100644 --- a/C4/Context.pm +++ b/C4/Context.pm @@ -689,9 +689,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.1.4