From faccbb2ced6ca2553be3c6b97417a6607ffbd760 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Fri, 19 Dec 2025 09:52:10 +0100 Subject: [PATCH] fix: Fix autorelease with a high number of untreated messages An issue happened when there was a high number of untreated messages associated to users without the "bypass human authentication" option. Indeed, the `getSearchQuery()` could return 1000 messages concerning these users, while the 1001th message (not returned) could have concerned a user with the "bypass" option enabled. Now, we iterate on the users with the option enabled and we get their untreated messages so we are sure to always load messages that need to be loaded. --- app/src/Command/AmavisAutoReleaseCommand.php | 32 ++++++++------------ app/src/Repository/UserRepository.php | 10 ++++++ 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/app/src/Command/AmavisAutoReleaseCommand.php b/app/src/Command/AmavisAutoReleaseCommand.php index 810709db..dff9b63a 100644 --- a/app/src/Command/AmavisAutoReleaseCommand.php +++ b/app/src/Command/AmavisAutoReleaseCommand.php @@ -20,7 +20,7 @@ )] class AmavisAutoReleaseCommand extends Command { - private int $batchSize = 1000; + private int $batchSize = 500; public function __construct( private MsgrcptSearchRepository $msgrcptSearchRepository, @@ -43,28 +43,20 @@ protected function execute(InputInterface $input, OutputInterface $output): int return Command::FAILURE; } - $searchQuery = $this->msgrcptSearchRepository->getSearchQuery( - null, - MessageStatus::UNTREATED - ); + $users = $this->userRepository->findAllWithoutHumanAuthentication(); - $messageRecipients = $searchQuery->setMaxResults($this->batchSize)->getResult(); + foreach ($users as $user) { + $searchQuery = $this->msgrcptSearchRepository->getSearchQuery( + $user, + MessageStatus::UNTREATED + ); - foreach ($messageRecipients as $messageRecipient) { - if ($messageRecipient->isAmavisReleaseOngoing()) { - continue; - } - - $user = $this->userRepository->findOneBy([ - 'email' => $messageRecipient->getRid()->getEmailClear() - ]); - - if (!$user) { - continue; - } + $messageRecipients = $searchQuery->setMaxResults($this->batchSize)->getResult(); - if ($user->getBypassHumanAuth()) { - $this->messageService->dispatchRelease($messageRecipient); + foreach ($messageRecipients as $messageRecipient) { + if (!$messageRecipient->isAmavisReleaseOngoing()) { + $this->messageService->dispatchRelease($messageRecipient); + } } } diff --git a/app/src/Repository/UserRepository.php b/app/src/Repository/UserRepository.php index da92e0b3..69e7ab8c 100644 --- a/app/src/Repository/UserRepository.php +++ b/app/src/Repository/UserRepository.php @@ -65,6 +65,16 @@ public function findOneByPrincipalName(string $principalName): ?User ->getOneOrNullResult(); } + /** + * @return User[] + */ + public function findAllWithoutHumanAuthentication(): array + { + return $this->findBy([ + 'bypassHumanAuth' => true, + ]); + } + /** * Return all users from active domains *