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 *