-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
[stable29] fix(Database): Use real idle-timer to prevent lastInsertId being reset on MariaDB/MySQL
#62709
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
backportbot
wants to merge
1
commit into
stable29
Choose a base branch
from
backport/62697/stable29
base: stable29
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[stable29] fix(Database): Use real idle-timer to prevent lastInsertId being reset on MariaDB/MySQL
#62709
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
lib/private/DB/Middleware/ConnectionActivityConnection.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| <?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\Connection; | ||
| use Doctrine\DBAL\Driver\Middleware\AbstractConnectionMiddleware; | ||
| use Doctrine\DBAL\Driver\PDO\Connection as PDOConnection; | ||
| use Doctrine\DBAL\Driver\Result; | ||
| use Doctrine\DBAL\Driver\Statement; | ||
|
|
||
| final class ConnectionActivityConnection extends AbstractConnectionMiddleware { | ||
| public function __construct( | ||
| private Connection $inner, | ||
| private ConnectionActivityNotifier $notifier, | ||
| ) { | ||
| parent::__construct($inner); | ||
| } | ||
|
|
||
| /** | ||
| * Kept working for consumers that reach the native PDO handle through the | ||
| * deprecated accessor, like SQLiteSessionInit: forwarding is intentionally | ||
| * preferred over migrating the callers, as those code paths get refactored | ||
| * with the DBAL 4 upgrade anyway. | ||
| */ | ||
| public function getWrappedConnection(): \PDO { | ||
| if (!$this->inner instanceof PDOConnection) { | ||
| throw new \LogicException('The wrapped connection is not a PDO based connection'); | ||
| } | ||
| return $this->inner->getWrappedConnection(); | ||
| } | ||
|
|
||
| #[\Override] | ||
| public function prepare(string $sql): Statement { | ||
| return new ConnectionActivityStatement(parent::prepare($sql), $this->notifier); | ||
| } | ||
|
|
||
| #[\Override] | ||
| public function query(string $sql): Result { | ||
| $result = parent::query($sql); | ||
| $this->notifier->notify(); | ||
| return $result; | ||
| } | ||
|
|
||
| #[\Override] | ||
| public function exec(string $sql): int { | ||
| $result = parent::exec($sql); | ||
| $this->notifier->notify(); | ||
| return $result; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <?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\AbstractDriverMiddleware; | ||
|
|
||
| final class ConnectionActivityDriver extends AbstractDriverMiddleware { | ||
| public function __construct( | ||
| Driver $driver, | ||
| private ConnectionActivityNotifier $notifier, | ||
| ) { | ||
| parent::__construct($driver); | ||
| } | ||
|
|
||
| #[\Override] | ||
| public function connect(array $params) { | ||
| return new ConnectionActivityConnection(parent::connect($params), $this->notifier); | ||
| } | ||
| } |
41 changes: 41 additions & 0 deletions
41
lib/private/DB/Middleware/ConnectionActivityMiddleware.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| <?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); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <?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; | ||
|
|
||
| /** | ||
| * Relays driver level activity to a listener that can only be registered | ||
| * after the middleware was created: middlewares are configured before the | ||
| * DriverManager constructs the connection wrapper that wants to listen. | ||
| */ | ||
| final class ConnectionActivityNotifier { | ||
| private ?\Closure $listener = null; | ||
|
|
||
| /** | ||
| * @param \Closure():void $listener | ||
| */ | ||
| public function setListener(\Closure $listener): void { | ||
| $this->listener = $listener; | ||
| } | ||
|
|
||
| public function notify(): void { | ||
| if ($this->listener !== null) { | ||
| ($this->listener)(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| <?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\Middleware\AbstractStatementMiddleware; | ||
| use Doctrine\DBAL\Driver\Result; | ||
| use Doctrine\DBAL\Driver\Statement; | ||
|
|
||
| final class ConnectionActivityStatement extends AbstractStatementMiddleware { | ||
| public function __construct( | ||
| Statement $statement, | ||
| private ConnectionActivityNotifier $notifier, | ||
| ) { | ||
| parent::__construct($statement); | ||
| } | ||
|
|
||
| #[\Override] | ||
| public function execute($params = null): Result { | ||
| $result = parent::execute($params); | ||
| $this->notifier->notify(); | ||
| return $result; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something wrong here?