From 941f83fc9f62009dfbb673ff89de52b17cd29e31 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 21 May 2026 09:07:44 +0000 Subject: [PATCH] fix(cleanup): remove expired wopi tokens with single delete query Co-authored-by: Julius Knorr Signed-off-by: Julius Knorr --- lib/Backgroundjobs/Cleanup.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/Backgroundjobs/Cleanup.php b/lib/Backgroundjobs/Cleanup.php index a77fb59892..088f04a006 100644 --- a/lib/Backgroundjobs/Cleanup.php +++ b/lib/Backgroundjobs/Cleanup.php @@ -6,17 +6,17 @@ namespace OCA\Richdocuments\Backgroundjobs; -use OCA\Richdocuments\Db\WopiMapper; use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\TimedJob; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; class Cleanup extends TimedJob { + private const EXPIRY_GRACE_PERIOD_SECONDS = 60; + public function __construct( ITimeFactory $time, private IDBConnection $db, - private WopiMapper $wopiMapper, ) { parent::__construct($time); @@ -27,7 +27,7 @@ protected function run($argument) { // Expire template mappings for file creation $query = $this->db->getQueryBuilder(); $query->delete('richdocuments_template') - ->where($query->expr()->lte('timestamp', $query->createNamedParameter(time() - 60, IQueryBuilder::PARAM_INT))); + ->where($query->expr()->lte('timestamp', $query->createNamedParameter(time() - self::EXPIRY_GRACE_PERIOD_SECONDS, IQueryBuilder::PARAM_INT))); $query->executeStatement(); // Expired WOPI access tokens @@ -35,10 +35,9 @@ protected function run($argument) { } private function cleanUpWopiTokens() { - $tokenIds = $this->wopiMapper->getExpiredTokenIds(1000); $query = $this->db->getQueryBuilder(); $query->delete('richdocuments_wopi') - ->where($query->expr()->in('id', $query->createNamedParameter($tokenIds, IQueryBuilder::PARAM_INT_ARRAY))); + ->where($query->expr()->lt('expiry', $query->createNamedParameter(time() - self::EXPIRY_GRACE_PERIOD_SECONDS, IQueryBuilder::PARAM_INT))); $query->executeStatement(); } }