diff options
author | Joas Schilling <coding@schilljs.com> | 2024-03-15 15:59:03 +0100 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2024-03-15 16:18:32 +0100 |
commit | 9148cf1ee70660d8a698e0cbc6bed09fbae27817 (patch) | |
tree | f0319fe942ce3d2316f3a6595745b7230cc7cd88 /lib | |
parent | 99cafa2ceb247aa5541cc80ca3b4fcbd9d07c91d (diff) |
fix(federation): Expire messages in the PCM cache
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/BackgroundJob/ExpireChatMessages.php | 3 | ||||
-rw-r--r-- | lib/Model/ProxyCacheMessageMapper.php | 9 | ||||
-rw-r--r-- | lib/Service/ProxyCacheMessageService.php | 6 |
3 files changed, 18 insertions, 0 deletions
diff --git a/lib/BackgroundJob/ExpireChatMessages.php b/lib/BackgroundJob/ExpireChatMessages.php index ac21dd2fe..4749d44a3 100644 --- a/lib/BackgroundJob/ExpireChatMessages.php +++ b/lib/BackgroundJob/ExpireChatMessages.php @@ -26,6 +26,7 @@ declare(strict_types=1); namespace OCA\Talk\BackgroundJob; use OCA\Talk\Chat\ChatManager; +use OCA\Talk\Service\ProxyCacheMessageService; use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\IJob; use OCP\BackgroundJob\TimedJob; @@ -35,6 +36,7 @@ class ExpireChatMessages extends TimedJob { public function __construct( ITimeFactory $timeFactory, private ChatManager $chatManager, + private ProxyCacheMessageService $pcmService, ) { parent::__construct($timeFactory); @@ -48,5 +50,6 @@ class ExpireChatMessages extends TimedJob { */ protected function run($argument): void { $this->chatManager->deleteExpiredMessages(); + $this->pcmService->deleteExpiredMessages(); } } diff --git a/lib/Model/ProxyCacheMessageMapper.php b/lib/Model/ProxyCacheMessageMapper.php index 2f1664949..f4fba2b24 100644 --- a/lib/Model/ProxyCacheMessageMapper.php +++ b/lib/Model/ProxyCacheMessageMapper.php @@ -71,4 +71,13 @@ class ProxyCacheMessageMapper extends QBMapper { return $this->findEntity($query); } + + public function deleteExpiredMessages(\DateTimeInterface $dateTime): int { + $query = $this->db->getQueryBuilder(); + $query->delete($this->getTableName()) + ->where($query->expr()->isNotNull('expire_datetime')) + ->andWhere($query->expr()->lte('expire_datetime', $query->createNamedParameter($dateTime, IQueryBuilder::PARAM_DATE))); + + return $query->executeStatement(); + } } diff --git a/lib/Service/ProxyCacheMessageService.php b/lib/Service/ProxyCacheMessageService.php index a7ebb1c8e..8a82fc885 100644 --- a/lib/Service/ProxyCacheMessageService.php +++ b/lib/Service/ProxyCacheMessageService.php @@ -35,6 +35,7 @@ use OCA\Talk\ResponseDefinitions; use OCA\Talk\Room; use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Http; +use OCP\AppFramework\Utility\ITimeFactory; use OCP\DB\Exception as DBException; use Psr\Log\LoggerInterface; @@ -45,6 +46,7 @@ class ProxyCacheMessageService { public function __construct( protected ProxyCacheMessageMapper $mapper, protected LoggerInterface $logger, + protected ITimeFactory $timeFactory, ) { } @@ -55,6 +57,10 @@ class ProxyCacheMessageService { return $this->mapper->findByRemote($remoteServerUrl, $remoteToken, $remoteMessageId); } + public function deleteExpiredMessages(): void { + $this->mapper->deleteExpiredMessages($this->timeFactory->getDateTime()); + } + /** * @throws \InvalidArgumentException * @throws CannotReachRemoteException |