Skip to content

Commit 2b90854

Browse files
authored
Merge pull request #5715 from nextcloud/backport/5688/stable34
[stable34] fix(cleanup): remove expired wopi tokens with single delete query
2 parents 576963f + 9170119 commit 2b90854

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

lib/Backgroundjobs/Cleanup.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77

88
namespace OCA\Richdocuments\Backgroundjobs;
99

10-
use OCA\Richdocuments\Db\WopiMapper;
1110
use OCP\AppFramework\Utility\ITimeFactory;
1211
use OCP\BackgroundJob\TimedJob;
1312
use OCP\DB\QueryBuilder\IQueryBuilder;
1413
use OCP\IDBConnection;
1514

1615
class Cleanup extends TimedJob {
16+
private const EXPIRY_GRACE_PERIOD_SECONDS = 60;
17+
1718
public function __construct(
1819
ITimeFactory $time,
1920
private IDBConnection $db,
20-
private WopiMapper $wopiMapper,
2121
) {
2222
parent::__construct($time);
2323

@@ -29,18 +29,17 @@ protected function run($argument) {
2929
// Expire template mappings for file creation
3030
$query = $this->db->getQueryBuilder();
3131
$query->delete('richdocuments_template')
32-
->where($query->expr()->lte('timestamp', $query->createNamedParameter(time() - 60, IQueryBuilder::PARAM_INT)));
32+
->where($query->expr()->lte('timestamp', $query->createNamedParameter(time() - self::EXPIRY_GRACE_PERIOD_SECONDS, IQueryBuilder::PARAM_INT)));
3333
$query->executeStatement();
3434

3535
// Expired WOPI access tokens
3636
$this->cleanUpWopiTokens();
3737
}
3838

3939
private function cleanUpWopiTokens() {
40-
$tokenIds = $this->wopiMapper->getExpiredTokenIds(1000);
4140
$query = $this->db->getQueryBuilder();
4241
$query->delete('richdocuments_wopi')
43-
->where($query->expr()->in('id', $query->createNamedParameter($tokenIds, IQueryBuilder::PARAM_INT_ARRAY)));
42+
->where($query->expr()->lt('expiry', $query->createNamedParameter(time() - self::EXPIRY_GRACE_PERIOD_SECONDS, IQueryBuilder::PARAM_INT)));
4443
$query->executeStatement();
4544
}
4645
}

0 commit comments

Comments
 (0)