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
32 changes: 12 additions & 20 deletions app/src/Command/AmavisAutoReleaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
)]
class AmavisAutoReleaseCommand extends Command
{
private int $batchSize = 1000;
private int $batchSize = 500;

public function __construct(
private MsgrcptSearchRepository $msgrcptSearchRepository,
Expand All @@ -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);
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions app/src/Repository/UserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down