diff --git a/application/Espo/Core/Webhook/Queue.php b/application/Espo/Core/Webhook/Queue.php index 2b0e49c1d4..26acec8b2d 100644 --- a/application/Espo/Core/Webhook/Queue.php +++ b/application/Espo/Core/Webhook/Queue.php @@ -112,17 +112,25 @@ class Queue $batchSize = $this->config->get('webhookBatchSize', self::BATCH_SIZE); $groupedItemList = $this->entityManager->getRepository('WebhookQueueItem') - ->select(['webhookId']) + ->select(['webhookId', 'number']) ->where([ - 'status' => 'Pending', - 'OR' => [ - ['processAt' => null], - ['processAt<=' => DateTime::getSystemNowString()], + 'number=s' => [ + 'entityType' => 'WebhookQueueItem', + 'selectParams' => [ + 'select' => ['MIN:number'], + 'whereClause' => [ + 'status' => 'Pending', + 'OR' => [ + ['processAt' => null], + ['processAt<=' => DateTime::getSystemNowString()], + ], + ], + 'groupBy' => ['webhookId'], + ] ], ]) - ->order('number') ->limit(0, $portionSize) - ->groupBy(['webhookId']) + ->order('number') ->find(); foreach ($groupedItemList as $group) {