Merge pull request #25550 from nextcloud/reconnectwrapper-wait-timeout

[20] change reconect wrapper to only check connection after inactivity
This commit is contained in:
Roeland Jago Douma 2021-02-09 21:14:46 +01:00 committed by GitHub
commit 3042a5a833
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 4 deletions

View File

@ -31,21 +31,22 @@ use Doctrine\DBAL\Driver;
class ReconnectWrapper extends \Doctrine\DBAL\Connection { class ReconnectWrapper extends \Doctrine\DBAL\Connection {
public const CHECK_CONNECTION_INTERVAL = 60; 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) { public function __construct(array $params, Driver $driver, Configuration $config = null, EventManager $eventManager = null) {
parent::__construct($params, $driver, $config, $eventManager); parent::__construct($params, $driver, $config, $eventManager);
$this->lastConnectionCheck = time(); $this->lastQuery = time();
} }
public function connect() { public function connect() {
$now = time(); $now = time();
$checkTime = $now - self::CHECK_CONNECTION_INTERVAL; $checkTime = $now - self::CHECK_CONNECTION_INTERVAL;
if ($this->lastConnectionCheck > $checkTime || $this->isTransactionActive()) { if ($this->lastQuery > $checkTime || $this->isTransactionActive()) {
$this->lastQuery = $now;
return parent::connect(); return parent::connect();
} else { } else {
$this->lastConnectionCheck = $now; $this->lastQuery = $now;
if (!$this->ping()) { if (!$this->ping()) {
$this->close(); $this->close();
} }