mirror of
https://github.com/nextcloud/server.git
synced 2026-09-30 14:17:52 +02:00
The previous implementation of the idle timer runs on a strict 30 second interval and sends a dummy `SELECT` statement to keep the connection open. This generates issues with the `lastInsertId` on long-running tasks (like our CI pipeline), as the MariaDB documentation clearly states: > If the last query wasn't an INSERT or UPDATE statement or if the modified table does not have a column with the AUTO_INCREMENT attribute and LAST_INSERT_ID was not used, this function will return zero. Source: https://mariadb.com/docs/connectors/mariadb-connector-c/api-functions/mysql_insert_id To mitigate that, this commit now uses a real idle-timer per connection instead. Assisted-by: ClaudeCode:claude-fable-5 Signed-off-by: David Dreschner <david.dreschner@nextcloud.com>
42 lines
1.2 KiB
PHP
42 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
namespace OC\DB\Middleware;
|
|
|
|
use Doctrine\DBAL\Driver;
|
|
use Doctrine\DBAL\Driver\Middleware;
|
|
|
|
/**
|
|
* Doctrine middleware reporting every query and statement execution back to
|
|
* the owning connection, so the idle timer of the connectivity check can be
|
|
* refreshed (see \OC\DB\Connection::refreshLastConnectionCheck()). Working on
|
|
* the driver level covers executions of prepared statements as well, which
|
|
* bypass the executeQuery() and executeStatement() methods of the connection.
|
|
*/
|
|
final class ConnectionActivityMiddleware implements Middleware {
|
|
private ConnectionActivityNotifier $notifier;
|
|
|
|
public function __construct() {
|
|
$this->notifier = new ConnectionActivityNotifier();
|
|
}
|
|
|
|
/**
|
|
* Hand the notifier to the connection that wants to listen, e.g. via the
|
|
* connection parameters.
|
|
*/
|
|
public function getNotifier(): ConnectionActivityNotifier {
|
|
return $this->notifier;
|
|
}
|
|
|
|
#[\Override]
|
|
public function wrap(Driver $driver): Driver {
|
|
return new ConnectionActivityDriver($driver, $this->notifier);
|
|
}
|
|
}
|