Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions lib/BackgroundJob/ExpireChatMessages.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
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;
Expand All @@ -35,6 +36,7 @@ class ExpireChatMessages extends TimedJob {
public function __construct(
ITimeFactory $timeFactory,
private ChatManager $chatManager,
private ProxyCacheMessageService $pcmService,
) {
parent::__construct($timeFactory);

Expand All @@ -48,5 +50,6 @@ public function __construct(
*/
protected function run($argument): void {
$this->chatManager->deleteExpiredMessages();
$this->pcmService->deleteExpiredMessages();
}
}
9 changes: 9 additions & 0 deletions lib/Model/ProxyCacheMessageMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,13 @@ public function findByRemote(string $remoteServerUrl, string $remoteToken, int $

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();
}
}
6 changes: 6 additions & 0 deletions lib/Service/ProxyCacheMessageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
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;

Expand All @@ -45,6 +46,7 @@ class ProxyCacheMessageService {
public function __construct(
protected ProxyCacheMessageMapper $mapper,
protected LoggerInterface $logger,
protected ITimeFactory $timeFactory,
) {
}

Expand All @@ -55,6 +57,10 @@ public function findByRemote(string $remoteServerUrl, string $remoteToken, int $
return $this->mapper->findByRemote($remoteServerUrl, $remoteToken, $remoteMessageId);
}

public function deleteExpiredMessages(): void {
$this->mapper->deleteExpiredMessages($this->timeFactory->getDateTime());
}

/**
* @throws \InvalidArgumentException
* @throws CannotReachRemoteException
Expand Down