From b51f32ec089d1cb6df8d34c67f467a3c882b4ff4 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 9 Feb 2021 16:30:59 +0100 Subject: [PATCH] change reconect wrapper to only check connection after inactivity instead of always checking every minute, only check the connection after a minute of inactivity. this should better reflect how idle timeouts of sql servers work and remove most of the cases where this check was previously done. Signed-off-by: Robin Appelman --- lib/private/DB/ReconnectWrapper.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/private/DB/ReconnectWrapper.php b/lib/private/DB/ReconnectWrapper.php index 9599d6b0fe..04f3ee0b2a 100644 --- a/lib/private/DB/ReconnectWrapper.php +++ b/lib/private/DB/ReconnectWrapper.php @@ -31,21 +31,22 @@ use Doctrine\DBAL\Driver; class ReconnectWrapper extends \Doctrine\DBAL\Connection { public const CHECK_CONNECTION_INTERVAL = 60; - private $lastConnectionCheck = null; + private $lastQuery = null; public function __construct(array $params, Driver $driver, Configuration $config = null, EventManager $eventManager = null) { parent::__construct($params, $driver, $config, $eventManager); - $this->lastConnectionCheck = time(); + $this->lastQuery = time(); } public function connect() { $now = time(); $checkTime = $now - self::CHECK_CONNECTION_INTERVAL; - if ($this->lastConnectionCheck > $checkTime || $this->isTransactionActive()) { + if ($this->lastQuery > $checkTime || $this->isTransactionActive()) { + $this->lastQuery = $now; return parent::connect(); } else { - $this->lastConnectionCheck = $now; + $this->lastQuery = $now; if (!$this->ping()) { $this->close(); }