From a943dbb420ca81e63b8ec3c1e508d55004424daf Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 12 May 2022 06:54:58 +0000 Subject: [PATCH] Introducing the "failed" counter --- database.sql | 3 ++- doc/database/db_post-delivery.md | 1 + src/Model/Post/Delivery.php | 13 ++++++++++++- src/Worker/APDelivery.php | 8 ++++++-- static/dbstructure.config.php | 3 ++- 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/database.sql b/database.sql index 1d632eb3fb..1508f358dc 100644 --- a/database.sql +++ b/database.sql @@ -1,6 +1,6 @@ -- ------------------------------------------ -- Friendica 2022.05-rc (Siberian Iris) --- DB_UPDATE_VERSION 1461 +-- DB_UPDATE_VERSION 1462 -- ------------------------------------------ @@ -1126,6 +1126,7 @@ CREATE TABLE IF NOT EXISTS `post-delivery` ( `uid` mediumint unsigned COMMENT 'Delivering user', `created` datetime DEFAULT '0001-01-01 00:00:00' COMMENT '', `command` varbinary(32) COMMENT '', + `failed` tinyint DEFAULT 0 COMMENT 'Number of times the delivery has failed', PRIMARY KEY(`uri-id`,`inbox-id`), INDEX `inbox-id_created` (`inbox-id`,`created`), INDEX `uid` (`uid`), diff --git a/doc/database/db_post-delivery.md b/doc/database/db_post-delivery.md index 79e858193a..8b149b5715 100644 --- a/doc/database/db_post-delivery.md +++ b/doc/database/db_post-delivery.md @@ -13,6 +13,7 @@ Fields | uid | Delivering user | mediumint unsigned | YES | | NULL | | | created | | datetime | YES | | 0001-01-01 00:00:00 | | | command | | varbinary(32) | YES | | NULL | | +| failed | Number of times the delivery has failed | tinyint | YES | | 0 | | Indexes ------------ diff --git a/src/Model/Post/Delivery.php b/src/Model/Post/Delivery.php index 8cd01c3a85..9ccfdc15a6 100644 --- a/src/Model/Post/Delivery.php +++ b/src/Model/Post/Delivery.php @@ -57,8 +57,19 @@ class Delivery DBA::delete('post-delivery', ['uri-id' => $uri_id, 'inbox-id' => ItemURI::getIdByURI($inbox)]); } + /** + * Increment "failed" counter for the given inbox and post + * + * @param integer $uri_id + * @param string $inbox + */ + public static function incrementFailed(int $uri_id, string $inbox) + { + return DBA::e('UPDATE `post-delivery` SET `failed` = `failed` + 1 WHERE `uri-id` = ? AND `inbox-id` = ?', $uri_id, ItemURI::getIdByURI($inbox)); + } + public static function selectForInbox(string $inbox) { - return DBA::selectToArray('post-delivery', [], ['inbox-id' => ItemURI::getIdByURI($inbox)], ['order' => ['created']]); + return DBA::selectToArray('post-delivery', [], ["`inbox-id` = ? AND `failed` < ?", ItemURI::getIdByURI($inbox), 15], ['order' => ['created']]); } } diff --git a/src/Worker/APDelivery.php b/src/Worker/APDelivery.php index 83e47172fc..4091a89bc7 100644 --- a/src/Worker/APDelivery.php +++ b/src/Worker/APDelivery.php @@ -131,8 +131,12 @@ class APDelivery $data = ActivityPub\Transmitter::createCachedActivityFromItem($item_id); if (!empty($data)) { $success = HTTPSignature::transmit($data, $inbox, $uid); - if ($success && $uri_id) { - Post\Delivery::remove($uri_id, $inbox); + if ($uri_id) { + if ($success) { + Post\Delivery::remove($uri_id, $inbox); + } else { + Post\Delivery::incrementFailed($uri_id, $inbox); + } } } } diff --git a/static/dbstructure.config.php b/static/dbstructure.config.php index 08634290b7..101e3da343 100644 --- a/static/dbstructure.config.php +++ b/static/dbstructure.config.php @@ -55,7 +55,7 @@ use Friendica\Database\DBA; if (!defined('DB_UPDATE_VERSION')) { - define('DB_UPDATE_VERSION', 1461); + define('DB_UPDATE_VERSION', 1462); } return [ @@ -1165,6 +1165,7 @@ return [ "uid" => ["type" => "mediumint unsigned", "foreign" => ["user" => "uid"], "comment" => "Delivering user"], "created" => ["type" => "datetime", "default" => DBA::NULL_DATETIME, "comment" => ""], "command" => ["type" => "varbinary(32)", "comment" => ""], + "failed" => ["type" => "tinyint", "default" => 0, "comment" => "Number of times the delivery has failed"], ], "indexes" => [ "PRIMARY" => ["uri-id", "inbox-id"],