Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions lib/Backgroundjobs/Cleanup.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,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);

Expand All @@ -29,18 +29,17 @@ 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
$this->cleanUpWopiTokens();
}

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();
}
}
Loading