diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2024-03-15 17:53:51 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-15 17:53:51 +0100 |
commit | 955c85150f702376b13776262fdc936188efb0fd (patch) | |
tree | ef8827b75c2bb375146f0b7831e75c8950ba36b0 | |
parent | 61bea6f438d1ebe4ca63dc0dbc4270ad480e92e2 (diff) | |
parent | 9148cf1ee70660d8a698e0cbc6bed09fbae27817 (diff) |
Merge pull request #11816 from nextcloud/bugfix/noid/expire-PCM-messages
fix(federation): Expire messages in the PCM cache
-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 |