From b0b67f1fde8658aefb1f4152894f381ae7f3a871 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 12 May 2022 12:43:49 +0000 Subject: [PATCH] Remove failing posts --- src/Model/Post/Delivery.php | 13 ++++++++++++- src/Worker/APDelivery.php | 9 ++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Model/Post/Delivery.php b/src/Model/Post/Delivery.php index 9ccfdc15a6..8d19f8c941 100644 --- a/src/Model/Post/Delivery.php +++ b/src/Model/Post/Delivery.php @@ -24,6 +24,7 @@ namespace Friendica\Model\Post; use Friendica\Database\DBA; use BadMethodCallException; use Friendica\Database\Database; +use Friendica\DI; use Friendica\Model\ItemURI; class Delivery @@ -57,6 +58,16 @@ class Delivery DBA::delete('post-delivery', ['uri-id' => $uri_id, 'inbox-id' => ItemURI::getIdByURI($inbox)]); } + /** + * Remove failed posts for an inbox + * + * @param string $inbox + */ + public static function removeFailed(string $inbox) + { + DBA::delete('post-delivery', ["`inbox-id` = ? AND `failed` >= ?", ItemURI::getIdByURI($inbox), DI::config()->get('system', 'worker_defer_limit')]); + } + /** * Increment "failed" counter for the given inbox and post * @@ -70,6 +81,6 @@ class Delivery public static function selectForInbox(string $inbox) { - return DBA::selectToArray('post-delivery', [], ["`inbox-id` = ? AND `failed` < ?", ItemURI::getIdByURI($inbox), 15], ['order' => ['created']]); + return DBA::selectToArray('post-delivery', [], ['inbox-id' => ItemURI::getIdByURI($inbox)], ['order' => ['created']]); } } diff --git a/src/Worker/APDelivery.php b/src/Worker/APDelivery.php index 4091a89bc7..caf89781e5 100644 --- a/src/Worker/APDelivery.php +++ b/src/Worker/APDelivery.php @@ -76,19 +76,18 @@ class APDelivery private static function deliver(string $inbox) { + Post\Delivery::removeFailed($inbox); + $uri_ids = []; $posts = Post\Delivery::selectForInbox($inbox); - $success = empty($posts); foreach ($posts as $post) { - if (self::deliverToInbox($post['command'], 0, $inbox, $post['uid'], [], $post['uri-id'])) { - $success = true; - } else { + if (!self::deliverToInbox($post['command'], 0, $inbox, $post['uid'], [], $post['uri-id'])) { $uri_ids[] = $post['uri-id']; } } - return ['success' => $success, 'uri_ids' => $uri_ids]; + return ['success' => empty($uri_ids), 'uri_ids' => $uri_ids]; } private static function deliverToInbox(string $cmd, int $item_id, string $inbox, int $uid, array $receivers, int $uri_id)