Skip to content

Commit faccbb2

Browse files
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.
1 parent 0ad0113 commit faccbb2

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

app/src/Command/AmavisAutoReleaseCommand.php

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
)]
2121
class AmavisAutoReleaseCommand extends Command
2222
{
23-
private int $batchSize = 1000;
23+
private int $batchSize = 500;
2424

2525
public function __construct(
2626
private MsgrcptSearchRepository $msgrcptSearchRepository,
@@ -43,28 +43,20 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4343
return Command::FAILURE;
4444
}
4545

46-
$searchQuery = $this->msgrcptSearchRepository->getSearchQuery(
47-
null,
48-
MessageStatus::UNTREATED
49-
);
46+
$users = $this->userRepository->findAllWithoutHumanAuthentication();
5047

51-
$messageRecipients = $searchQuery->setMaxResults($this->batchSize)->getResult();
48+
foreach ($users as $user) {
49+
$searchQuery = $this->msgrcptSearchRepository->getSearchQuery(
50+
$user,
51+
MessageStatus::UNTREATED
52+
);
5253

53-
foreach ($messageRecipients as $messageRecipient) {
54-
if ($messageRecipient->isAmavisReleaseOngoing()) {
55-
continue;
56-
}
57-
58-
$user = $this->userRepository->findOneBy([
59-
'email' => $messageRecipient->getRid()->getEmailClear()
60-
]);
61-
62-
if (!$user) {
63-
continue;
64-
}
54+
$messageRecipients = $searchQuery->setMaxResults($this->batchSize)->getResult();
6555

66-
if ($user->getBypassHumanAuth()) {
67-
$this->messageService->dispatchRelease($messageRecipient);
56+
foreach ($messageRecipients as $messageRecipient) {
57+
if (!$messageRecipient->isAmavisReleaseOngoing()) {
58+
$this->messageService->dispatchRelease($messageRecipient);
59+
}
6860
}
6961
}
7062

app/src/Repository/UserRepository.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ public function findOneByPrincipalName(string $principalName): ?User
6565
->getOneOrNullResult();
6666
}
6767

68+
/**
69+
* @return User[]
70+
*/
71+
public function findAllWithoutHumanAuthentication(): array
72+
{
73+
return $this->findBy([
74+
'bypassHumanAuth' => true,
75+
]);
76+
}
77+
6878
/**
6979
* Return all users from active domains
7080
*

0 commit comments

Comments
 (0)