diff options
author | Christoph Wurst <ChristophWurst@users.noreply.github.com> | 2024-06-19 18:04:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-19 18:04:36 +0200 |
commit | 902d77ee7d7f8a6e6b060549edcd2dfb9010e748 (patch) | |
tree | d35c3495a3c4570202e6b1a346ec43c45d13a0de | |
parent | 18cf61df9f641681b599ed2d693ac09803ef5370 (diff) | |
parent | 169eedabf94504ce126c2221a96791967c2b3ec1 (diff) | |
download | nextcloud-server-902d77ee7d7f8a6e6b060549edcd2dfb9010e748.tar.gz nextcloud-server-902d77ee7d7f8a6e6b060549edcd2dfb9010e748.zip |
Merge pull request #45968 from nextcloud/fix/dav/limit-sync-token-created-at-updates
fix(dav): Limit number of UPDATES for sync token created_at
-rw-r--r-- | apps/dav/lib/Migration/Version1025Date20240308063933.php | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/apps/dav/lib/Migration/Version1025Date20240308063933.php b/apps/dav/lib/Migration/Version1025Date20240308063933.php index 4c506f29024..55ab387b69c 100644 --- a/apps/dav/lib/Migration/Version1025Date20240308063933.php +++ b/apps/dav/lib/Migration/Version1025Date20240308063933.php @@ -10,6 +10,7 @@ declare(strict_types=1); namespace OCA\DAV\Migration; use Closure; +use OCP\AppFramework\Services\IAppConfig; use OCP\DB\ISchemaWrapper; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\DB\Types; @@ -19,10 +20,13 @@ use OCP\Migration\SimpleMigrationStep; class Version1025Date20240308063933 extends SimpleMigrationStep { + private IAppConfig $appConfig; private IDBConnection $db; - public function __construct(IDBConnection $db) { + public function __construct(IAppConfig $appConfig, + IDBConnection $db) { $this->db = $db; + $this->appConfig = $appConfig; } /** @@ -50,7 +54,22 @@ class Version1025Date20240308063933 extends SimpleMigrationStep { } public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options): void { + // The threshold is higher than the default of \OCA\DAV\BackgroundJob\PruneOutdatedSyncTokensJob + // but small enough to fit into a cluster transaction size. + // For a 50k users instance that would still keep 10 changes on average. + $limit = max(1, (int) $this->appConfig->getAppValue('totalNumberOfSyncTokensToKeep', '500000')); + foreach (['addressbookchanges', 'calendarchanges'] as $tableName) { + $thresholdSelect = $this->db->getQueryBuilder(); + $thresholdSelect->select('id') + ->from($tableName) + ->orderBy('id', 'desc') + ->setFirstResult($limit) + ->setMaxResults(1); + $oldestIdResult = $thresholdSelect->executeQuery(); + $oldestId = $oldestIdResult->fetchColumn(); + $oldestIdResult->closeCursor(); + $qb = $this->db->getQueryBuilder(); $update = $qb->update($tableName) @@ -59,7 +78,15 @@ class Version1025Date20240308063933 extends SimpleMigrationStep { $qb->expr()->eq('created_at', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT)), ); + // If there is a lot of data we only set timestamp for the most recent rows + // because the rest will be deleted by \OCA\DAV\BackgroundJob\PruneOutdatedSyncTokensJob + // anyway. + if ($oldestId !== false) { + $update->andWhere($qb->expr()->gt('id', $qb->createNamedParameter($oldestId, IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT)); + } + $updated = $update->executeStatement(); + $output->debug('Added a default creation timestamp to ' . $updated . ' rows in ' . $tableName); } } |