"item-delivery-data" is now "post-delivery-data"

This commit is contained in:
Michael 2020-05-02 19:34:02 +00:00
parent 92cf4879e5
commit 098ba4a667
8 changed files with 147 additions and 120 deletions

View file

@ -1,6 +1,6 @@
-- ------------------------------------------ -- ------------------------------------------
-- Friendica 2020.06-dev (Red Hot Poker) -- Friendica 2020.06-dev (Red Hot Poker)
-- DB_UPDATE_VERSION 1341 -- DB_UPDATE_VERSION 1343
-- ------------------------------------------ -- ------------------------------------------
@ -666,7 +666,8 @@ CREATE TABLE IF NOT EXISTS `item` (
INDEX `uid_eventid` (`uid`,`event-id`), INDEX `uid_eventid` (`uid`,`event-id`),
INDEX `icid` (`icid`), INDEX `icid` (`icid`),
INDEX `iaid` (`iaid`), INDEX `iaid` (`iaid`),
INDEX `psid_wall` (`psid`,`wall`) INDEX `psid_wall` (`psid`,`wall`),
INDEX `uri-id` (`uri-id`)
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Structure for all posts'; ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Structure for all posts';
-- --
@ -714,24 +715,6 @@ CREATE TABLE IF NOT EXISTS `item-content` (
INDEX `uri-id` (`uri-id`) INDEX `uri-id` (`uri-id`)
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Content for all posts'; ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Content for all posts';
--
-- TABLE item-delivery-data
--
CREATE TABLE IF NOT EXISTS `item-delivery-data` (
`iid` int unsigned NOT NULL COMMENT 'Item id',
`postopts` text COMMENT 'External post connectors add their network name to this comma-separated string to identify that they should be delivered to these networks during delivery',
`inform` mediumtext COMMENT 'Additional receivers of the linked item',
`queue_count` mediumint NOT NULL DEFAULT 0 COMMENT 'Initial number of delivery recipients, used as item.delivery_queue_count',
`queue_done` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries, used as item.delivery_queue_done',
`queue_failed` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of unsuccessful deliveries, used as item.delivery_queue_failed',
`activitypub` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via ActivityPub',
`dfrn` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via DFRN',
`legacy_dfrn` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via legacy DFRN',
`diaspora` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via Diaspora',
`ostatus` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via OStatus',
PRIMARY KEY(`iid`)
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Delivery data for items';
-- --
-- TABLE item-uri -- TABLE item-uri
-- --
@ -1187,6 +1170,24 @@ CREATE TABLE IF NOT EXISTS `tag` (
INDEX `url` (`url`) INDEX `url` (`url`)
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='tags and mentions'; ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='tags and mentions';
--
-- TABLE post-delivery-data
--
CREATE TABLE IF NOT EXISTS `post-delivery-data` (
`uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
`postopts` text COMMENT 'External post connectors add their network name to this comma-separated string to identify that they should be delivered to these networks during delivery',
`inform` mediumtext COMMENT 'Additional receivers of the linked item',
`queue_count` mediumint NOT NULL DEFAULT 0 COMMENT 'Initial number of delivery recipients, used as item.delivery_queue_count',
`queue_done` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries, used as item.delivery_queue_done',
`queue_failed` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of unsuccessful deliveries, used as item.delivery_queue_failed',
`activitypub` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via ActivityPub',
`dfrn` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via DFRN',
`legacy_dfrn` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via legacy DFRN',
`diaspora` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via Diaspora',
`ostatus` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via OStatus',
PRIMARY KEY(`uri-id`)
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Delivery data for items';
-- --
-- TABLE post-tag -- TABLE post-tag
-- --
@ -1577,6 +1578,27 @@ CREATE VIEW `pending-view` AS SELECT
INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid` INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid`
INNER JOIN `user` ON `register`.`uid` = `user`.`uid`; INNER JOIN `user` ON `register`.`uid` = `user`.`uid`;
--
-- VIEW tag-search-view
--
DROP VIEW IF EXISTS `tag-search-view`;
CREATE VIEW `tag-search-view` AS SELECT
`post-tag`.`uri-id` AS `uri-id`,
`item`.`id` AS `iid`,
`item`.`uri` AS `uri`,
`item`.`guid` AS `guid`,
`item`.`uid` AS `uid`,
`item`.`private` AS `private`,
`item`.`wall` AS `wall`,
`item`.`origin` AS `origin`,
`item`.`gravity` AS `gravity`,
`item`.`received` AS `received`,
`tag`.`name` AS `name`
FROM `post-tag`
INNER JOIN `tag` ON `tag`.`id` = `post-tag`.`tid`
INNER JOIN `item` ON `item`.`uri-id` = `post-tag`.`uri-id`
WHERE `post-tag`.`type` = 1;
-- --
-- VIEW workerqueue-view -- VIEW workerqueue-view
-- --

View file

@ -283,7 +283,7 @@ class Item
// Fetch data from the item-content table whenever there is content there // Fetch data from the item-content table whenever there is content there
if (self::isLegacyMode()) { if (self::isLegacyMode()) {
$legacy_fields = array_merge(ItemDeliveryData::LEGACY_FIELD_LIST, self::MIXED_CONTENT_FIELDLIST); $legacy_fields = array_merge(Post\DeliveryData::LEGACY_FIELD_LIST, self::MIXED_CONTENT_FIELDLIST);
foreach ($legacy_fields as $field) { foreach ($legacy_fields as $field) {
if (empty($row[$field]) && !empty($row['internal-item-' . $field])) { if (empty($row[$field]) && !empty($row['internal-item-' . $field])) {
$row[$field] = $row['internal-item-' . $field]; $row[$field] = $row['internal-item-' . $field];
@ -687,7 +687,7 @@ class Item
$fields['item-content'] = array_merge(self::CONTENT_FIELDLIST, self::MIXED_CONTENT_FIELDLIST); $fields['item-content'] = array_merge(self::CONTENT_FIELDLIST, self::MIXED_CONTENT_FIELDLIST);
$fields['item-delivery-data'] = array_merge(ItemDeliveryData::LEGACY_FIELD_LIST, ItemDeliveryData::FIELD_LIST); $fields['post-delivery-data'] = array_merge(Post\DeliveryData::LEGACY_FIELD_LIST, Post\DeliveryData::FIELD_LIST);
$fields['permissionset'] = ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid']; $fields['permissionset'] = ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid'];
@ -809,8 +809,8 @@ class Item
$joins .= " LEFT JOIN `item-content` ON `item-content`.`uri-id` = `item`.`uri-id`"; $joins .= " LEFT JOIN `item-content` ON `item-content`.`uri-id` = `item`.`uri-id`";
} }
if (strpos($sql_commands, "`item-delivery-data`.") !== false) { if (strpos($sql_commands, "`post-delivery-data`.") !== false) {
$joins .= " LEFT JOIN `item-delivery-data` ON `item-delivery-data`.`iid` = `item`.`id`"; $joins .= " LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `item`.`uri-id` AND `item`.`origin`";
} }
if (strpos($sql_commands, "`permissionset`.") !== false) { if (strpos($sql_commands, "`permissionset`.") !== false) {
@ -850,7 +850,7 @@ class Item
$selected[] = 'internal-user-ignored'; $selected[] = 'internal-user-ignored';
} }
$legacy_fields = array_merge(ItemDeliveryData::LEGACY_FIELD_LIST, self::MIXED_CONTENT_FIELDLIST); $legacy_fields = array_merge(Post\DeliveryData::LEGACY_FIELD_LIST, self::MIXED_CONTENT_FIELDLIST);
$selection = []; $selection = [];
foreach ($fields as $table => $table_fields) { foreach ($fields as $table => $table_fields) {
@ -936,7 +936,7 @@ class Item
} }
} }
$delivery_data = ItemDeliveryData::extractFields($fields); $delivery_data = Post\DeliveryData::extractFields($fields);
$clear_fields = ['bookmark', 'type', 'author-name', 'author-avatar', 'author-link', 'owner-name', 'owner-avatar', 'owner-link', 'postopts', 'inform']; $clear_fields = ['bookmark', 'type', 'author-name', 'author-avatar', 'author-link', 'owner-name', 'owner-avatar', 'owner-link', 'postopts', 'inform'];
foreach ($clear_fields as $field) { foreach ($clear_fields as $field) {
@ -1038,7 +1038,7 @@ class Item
} }
} }
ItemDeliveryData::update($item['id'], $delivery_data); Post\DeliveryData::update($item['uri-id'], $delivery_data);
self::updateThread($item['id']); self::updateThread($item['id']);
@ -1118,7 +1118,7 @@ class Item
{ {
Logger::info('Mark item for deletion by id', ['id' => $item_id, 'callstack' => System::callstack()]); Logger::info('Mark item for deletion by id', ['id' => $item_id, 'callstack' => System::callstack()]);
// locate item to be deleted // locate item to be deleted
$fields = ['id', 'uri', 'uid', 'parent', 'parent-uri', 'origin', $fields = ['id', 'uri', 'uri-id', 'uid', 'parent', 'parent-uri', 'origin',
'deleted', 'file', 'resource-id', 'event-id', 'attach', 'deleted', 'file', 'resource-id', 'event-id', 'attach',
'verb', 'object-type', 'object', 'target', 'contact-id', 'verb', 'object-type', 'object', 'target', 'contact-id',
'icid', 'iaid', 'psid']; 'icid', 'iaid', 'psid'];
@ -1202,7 +1202,7 @@ class Item
self::markForDeletion(['uri' => $item['uri'], 'uid' => 0, 'deleted' => false], $priority); self::markForDeletion(['uri' => $item['uri'], 'uid' => 0, 'deleted' => false], $priority);
} }
ItemDeliveryData::delete($item['id']); Post\DeliveryData::delete($item['uri-id']);
// We don't delete the item-activity here, since we need some of the data for ActivityPub // We don't delete the item-activity here, since we need some of the data for ActivityPub
@ -1903,7 +1903,8 @@ class Item
self::insertContent($item); self::insertContent($item);
} }
$delivery_data = ItemDeliveryData::extractFields($item); $postfields = $item;
$delivery_data = Post\DeliveryData::extractFields($postfields);
unset($item['postopts']); unset($item['postopts']);
unset($item['inform']); unset($item['inform']);
@ -2007,7 +2008,7 @@ class Item
} }
if (!empty($item['origin']) || !empty($item['wall']) || !empty($delivery_data['postopts']) || !empty($delivery_data['inform'])) { if (!empty($item['origin']) || !empty($item['wall']) || !empty($delivery_data['postopts']) || !empty($delivery_data['inform'])) {
ItemDeliveryData::insert($current_post, $delivery_data); Post\DeliveryData::insert($item['uri-id'], $delivery_data);
} }
DBA::commit(); DBA::commit();

View file

@ -19,12 +19,12 @@
* *
*/ */
namespace Friendica\Model; namespace Friendica\Model\Post;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use \BadMethodCallException; use \BadMethodCallException;
class ItemDeliveryData class DeliveryData
{ {
const LEGACY_FIELD_LIST = [ const LEGACY_FIELD_LIST = [
// Legacy fields moved from item table // Legacy fields moved from item table
@ -55,7 +55,7 @@ class ItemDeliveryData
public static function extractFields(array &$fields) public static function extractFields(array &$fields)
{ {
$delivery_data = []; $delivery_data = [];
foreach (array_merge(ItemDeliveryData::FIELD_LIST, ItemDeliveryData::LEGACY_FIELD_LIST) as $key => $field) { foreach (array_merge(self::FIELD_LIST, self::LEGACY_FIELD_LIST) as $key => $field) {
if (is_int($key) && isset($fields[$field])) { if (is_int($key) && isset($fields[$field])) {
// Legacy field moved from item table // Legacy field moved from item table
$delivery_data[$field] = $fields[$field]; $delivery_data[$field] = $fields[$field];
@ -71,16 +71,16 @@ class ItemDeliveryData
} }
/** /**
* Increments the queue_done for the given item ID. * Increments the queue_done for the given URI ID.
* *
* Avoids racing condition between multiple delivery threads. * Avoids racing condition between multiple delivery threads.
* *
* @param integer $item_id * @param integer $uri_id
* @param integer $protocol * @param integer $protocol
* @return bool * @return bool
* @throws \Exception * @throws \Exception
*/ */
public static function incrementQueueDone($item_id, $protocol = 0) public static function incrementQueueDone(int $uri_id, int $protocol = 0)
{ {
$sql = ''; $sql = '';
@ -102,69 +102,69 @@ class ItemDeliveryData
break; break;
} }
return DBA::e('UPDATE `item-delivery-data` SET `queue_done` = `queue_done` + 1' . $sql . ' WHERE `iid` = ?', $item_id); return DBA::e('UPDATE `post-delivery-data` SET `queue_done` = `queue_done` + 1' . $sql . ' WHERE `uri-id` = ?', $uri_id);
} }
/** /**
* Increments the queue_failed for the given item ID. * Increments the queue_failed for the given URI ID.
* *
* Avoids racing condition between multiple delivery threads. * Avoids racing condition between multiple delivery threads.
* *
* @param integer $item_id * @param integer $uri_id
* @return bool * @return bool
* @throws \Exception * @throws \Exception
*/ */
public static function incrementQueueFailed($item_id) public static function incrementQueueFailed(int $uri_id)
{ {
return DBA::e('UPDATE `item-delivery-data` SET `queue_failed` = `queue_failed` + 1 WHERE `iid` = ?', $item_id); return DBA::e('UPDATE `post-delivery-data` SET `queue_failed` = `queue_failed` + 1 WHERE `uri-id` = ?', $uri_id);
} }
/** /**
* Increments the queue_count for the given item ID. * Increments the queue_count for the given URI ID.
* *
* @param integer $item_id * @param integer $uri_id
* @param integer $increment * @param integer $increment
* @return bool * @return bool
* @throws \Exception * @throws \Exception
*/ */
public static function incrementQueueCount(int $item_id, int $increment = 1) public static function incrementQueueCount(int $uri_id, int $increment = 1)
{ {
return DBA::e('UPDATE `item-delivery-data` SET `queue_count` = `queue_count` + ? WHERE `iid` = ?', $increment, $item_id); return DBA::e('UPDATE `post-delivery-data` SET `queue_count` = `queue_count` + ? WHERE `uri-id` = ?', $increment, $uri_id);
} }
/** /**
* Insert a new item delivery data entry * Insert a new URI delivery data entry
* *
* @param integer $item_id * @param integer $uri_id
* @param array $fields * @param array $fields
* @return bool * @return bool
* @throws \Exception * @throws \Exception
*/ */
public static function insert($item_id, array $fields) public static function insert(int $uri_id, array $fields)
{ {
if (empty($item_id)) { if (empty($uri_id)) {
throw new BadMethodCallException('Empty item_id'); throw new BadMethodCallException('Empty URI_id');
} }
$fields['iid'] = $item_id; $fields['uri-id'] = $uri_id;
return DBA::insert('item-delivery-data', $fields); return DBA::insert('post-delivery-data', $fields);
} }
/** /**
* Update/Insert item delivery data * Update/Insert URI delivery data
* *
* If you want to update queue_done, please use incrementQueueDone instead. * If you want to update queue_done, please use incrementQueueDone instead.
* *
* @param integer $item_id * @param integer $uri_id
* @param array $fields * @param array $fields
* @return bool * @return bool
* @throws \Exception * @throws \Exception
*/ */
public static function update($item_id, array $fields) public static function update(int $uri_id, array $fields)
{ {
if (empty($item_id)) { if (empty($uri_id)) {
throw new BadMethodCallException('Empty item_id'); throw new BadMethodCallException('Empty URI_id');
} }
if (empty($fields)) { if (empty($fields)) {
@ -172,22 +172,22 @@ class ItemDeliveryData
return true; return true;
} }
return DBA::update('item-delivery-data', $fields, ['iid' => $item_id], true); return DBA::update('post-delivery-data', $fields, ['uri-id' => $uri_id], true);
} }
/** /**
* Delete item delivery data * Delete URI delivery data
* *
* @param integer $item_id * @param integer $uri_id
* @return bool * @return bool
* @throws \Exception * @throws \Exception
*/ */
public static function delete($item_id) public static function delete(int $uri_id)
{ {
if (empty($item_id)) { if (empty($uri_id)) {
throw new BadMethodCallException('Empty item_id'); throw new BadMethodCallException('Empty URI_id');
} }
return DBA::delete('item-delivery-data', ['iid' => $item_id]); return DBA::delete('post-delivery-data', ['uri-id' => $uri_id]);
} }
} }

View file

@ -36,8 +36,8 @@ use Friendica\Model\Conversation;
use Friendica\Model\GContact; use Friendica\Model\GContact;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Model\ItemURI; use Friendica\Model\ItemURI;
use Friendica\Model\ItemDeliveryData;
use Friendica\Model\Mail; use Friendica\Model\Mail;
use Friendica\Model\Post;
use Friendica\Model\Tag; use Friendica\Model\Tag;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Network\Probe; use Friendica\Network\Probe;
@ -2293,7 +2293,7 @@ class Diaspora
} }
// Send all existing comments and likes to the requesting server // Send all existing comments and likes to the requesting server
$comments = Item::select(['id', 'parent', 'verb', 'self'], ['parent' => $item['id']]); $comments = Item::select(['id', 'uri-id', 'parent', 'verb', 'self'], ['parent' => $item['id']]);
while ($comment = Item::fetch($comments)) { while ($comment = Item::fetch($comments)) {
if ($comment['id'] == $comment['parent']) { if ($comment['id'] == $comment['parent']) {
continue; continue;
@ -2301,7 +2301,7 @@ class Diaspora
Logger::info('Deliver participation', ['item' => $comment['id'], 'contact' => $contact_id]); Logger::info('Deliver participation', ['item' => $comment['id'], 'contact' => $contact_id]);
if (Worker::add(PRIORITY_HIGH, 'Delivery', Delivery::POST, $comment['id'], $contact_id)) { if (Worker::add(PRIORITY_HIGH, 'Delivery', Delivery::POST, $comment['id'], $contact_id)) {
ItemDeliveryData::incrementQueueCount($comment['id'], 1); Post\DeliveryData::incrementQueueCount($comment['uri-id'], 1);
} }
} }
DBA::close($comments); DBA::close($comments);

View file

@ -23,7 +23,8 @@ namespace Friendica\Worker;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\Core\Worker; use Friendica\Core\Worker;
use Friendica\Model\ItemDeliveryData; use Friendica\Model\Item;
use Friendica\Model\Post;
use Friendica\Protocol\ActivityPub; use Friendica\Protocol\ActivityPub;
use Friendica\Util\HTTPSignature; use Friendica\Util\HTTPSignature;
@ -67,10 +68,13 @@ class APDelivery
} }
} }
// This should never fail and is temporariy (until the move to )
$item = Item::selectFirst(['uri-id'], ['id' => $target_id]);
if (!$success && !Worker::defer() && in_array($cmd, [Delivery::POST])) { if (!$success && !Worker::defer() && in_array($cmd, [Delivery::POST])) {
ItemDeliveryData::incrementQueueFailed($target_id); Post\DeliveryData::incrementQueueFailed($item['uri-id']);
} elseif ($success && in_array($cmd, [Delivery::POST])) { } elseif ($success && in_array($cmd, [Delivery::POST])) {
ItemDeliveryData::incrementQueueDone($target_id, ItemDeliveryData::ACTIVITYPUB); Post\DeliveryData::incrementQueueDone($item['uri-id'], Post\DeliveryData::ACTIVITYPUB);
} }
} }
} }

View file

@ -58,14 +58,14 @@ class Delivery
if ($cmd == self::MAIL) { if ($cmd == self::MAIL) {
$target_item = DBA::selectFirst('mail', [], ['id' => $target_id]); $target_item = DBA::selectFirst('mail', [], ['id' => $target_id]);
if (!DBA::isResult($target_item)) { if (!DBA::isResult($target_item)) {
self::setFailedQueue($cmd, $target_id); self::setFailedQueue($cmd, $target_item);
return; return;
} }
$uid = $target_item['uid']; $uid = $target_item['uid'];
} elseif ($cmd == self::SUGGESTION) { } elseif ($cmd == self::SUGGESTION) {
$target_item = DBA::selectFirst('fsuggest', [], ['id' => $target_id]); $target_item = DBA::selectFirst('fsuggest', [], ['id' => $target_id]);
if (!DBA::isResult($target_item)) { if (!DBA::isResult($target_item)) {
self::setFailedQueue($cmd, $target_id); self::setFailedQueue($cmd, $target_item);
return; return;
} }
$uid = $target_item['uid']; $uid = $target_item['uid'];
@ -75,7 +75,7 @@ class Delivery
} else { } else {
$item = Model\Item::selectFirst(['parent'], ['id' => $target_id]); $item = Model\Item::selectFirst(['parent'], ['id' => $target_id]);
if (!DBA::isResult($item) || empty($item['parent'])) { if (!DBA::isResult($item) || empty($item['parent'])) {
self::setFailedQueue($cmd, $target_id); self::setFailedQueue($cmd, $target_item);
return; return;
} }
$parent_id = intval($item['parent']); $parent_id = intval($item['parent']);
@ -97,13 +97,13 @@ class Delivery
if (empty($target_item)) { if (empty($target_item)) {
Logger::log('Item ' . $target_id . "wasn't found. Quitting here."); Logger::log('Item ' . $target_id . "wasn't found. Quitting here.");
self::setFailedQueue($cmd, $target_id); self::setFailedQueue($cmd, $target_item);
return; return;
} }
if (empty($parent)) { if (empty($parent)) {
Logger::log('Parent ' . $parent_id . ' for item ' . $target_id . "wasn't found. Quitting here."); Logger::log('Parent ' . $parent_id . ' for item ' . $target_id . "wasn't found. Quitting here.");
self::setFailedQueue($cmd, $target_id); self::setFailedQueue($cmd, $target_item);
return; return;
} }
@ -113,7 +113,7 @@ class Delivery
$uid = $target_item['uid']; $uid = $target_item['uid'];
} else { } else {
Logger::log('Only public users for item ' . $target_id, Logger::DEBUG); Logger::log('Only public users for item ' . $target_id, Logger::DEBUG);
self::setFailedQueue($cmd, $target_id); self::setFailedQueue($cmd, $target_item);
return; return;
} }
@ -127,7 +127,7 @@ class Delivery
if (!empty($contact_id) && Model\Contact::isArchived($contact_id)) { if (!empty($contact_id) && Model\Contact::isArchived($contact_id)) {
Logger::info('Contact is archived', ['id' => $contact_id, 'cmd' => $cmd, 'item' => $target_item['id']]); Logger::info('Contact is archived', ['id' => $contact_id, 'cmd' => $cmd, 'item' => $target_item['id']]);
self::setFailedQueue($cmd, $target_id); self::setFailedQueue($cmd, $target_item);
return; return;
} }
@ -187,7 +187,7 @@ class Delivery
$owner = Model\User::getOwnerDataById($uid); $owner = Model\User::getOwnerDataById($uid);
if (!DBA::isResult($owner)) { if (!DBA::isResult($owner)) {
self::setFailedQueue($cmd, $target_id); self::setFailedQueue($cmd, $target_item);
return; return;
} }
@ -196,12 +196,12 @@ class Delivery
['id' => $contact_id, 'blocked' => false, 'pending' => false, 'self' => false] ['id' => $contact_id, 'blocked' => false, 'pending' => false, 'self' => false]
); );
if (!DBA::isResult($contact)) { if (!DBA::isResult($contact)) {
self::setFailedQueue($cmd, $target_id); self::setFailedQueue($cmd, $target_item);
return; return;
} }
if (Network::isUrlBlocked($contact['url'])) { if (Network::isUrlBlocked($contact['url'])) {
self::setFailedQueue($cmd, $target_id); self::setFailedQueue($cmd, $target_item);
return; return;
} }
@ -242,16 +242,16 @@ class Delivery
/** /**
* Increased the "failed" counter in the item delivery data * Increased the "failed" counter in the item delivery data
* *
* @param string $cmd Command * @param string $cmd Command
* @param integer $id Item id * @param array $item Item array
*/ */
private static function setFailedQueue(string $cmd, int $id) private static function setFailedQueue(string $cmd, array $item)
{ {
if (!in_array($cmd, [Delivery::POST, Delivery::POKE])) { if (!in_array($cmd, [Delivery::POST, Delivery::POKE])) {
return; return;
} }
Model\ItemDeliveryData::incrementQueueFailed($id); Model\Post\DeliveryData::incrementQueueFailed($item['uri-id'] ?? $item['id']);
} }
/** /**
@ -335,13 +335,13 @@ class Delivery
DFRN::import($atom, $target_importer); DFRN::import($atom, $target_importer);
if (in_array($cmd, [Delivery::POST, Delivery::POKE])) { if (in_array($cmd, [Delivery::POST, Delivery::POKE])) {
Model\ItemDeliveryData::incrementQueueDone($target_item['id'], Model\ItemDeliveryData::DFRN); Model\Post\DeliveryData::incrementQueueDone($target_item['uri-id'], Model\Post\DeliveryData::DFRN);
} }
return; return;
} }
$protocol = Model\ItemDeliveryData::DFRN; $protocol = Model\Post\DeliveryData::DFRN;
// We don't have a relationship with contacts on a public post. // We don't have a relationship with contacts on a public post.
// Se we transmit with the new method and via Diaspora as a fallback // Se we transmit with the new method and via Diaspora as a fallback
@ -357,9 +357,9 @@ class Delivery
if (in_array($cmd, [Delivery::POST, Delivery::POKE])) { if (in_array($cmd, [Delivery::POST, Delivery::POKE])) {
if (($deliver_status >= 200) && ($deliver_status <= 299)) { if (($deliver_status >= 200) && ($deliver_status <= 299)) {
Model\ItemDeliveryData::incrementQueueDone($target_item['id'], $protocol); Model\Post\DeliveryData::incrementQueueDone($target_item['uri-id'], $protocol);
} else { } else {
Model\ItemDeliveryData::incrementQueueFailed($target_item['id']); Model\Post\DeliveryData::incrementQueueFailed($target_item['uri-id']);
} }
} }
return; return;
@ -376,11 +376,11 @@ class Delivery
if ($deliver_status < 200) { if ($deliver_status < 200) {
// Legacy DFRN // Legacy DFRN
$deliver_status = DFRN::deliver($owner, $contact, $atom); $deliver_status = DFRN::deliver($owner, $contact, $atom);
$protocol = Model\ItemDeliveryData::LEGACY_DFRN; $protocol = Model\Post\DeliveryData::LEGACY_DFRN;
} }
} else { } else {
$deliver_status = DFRN::deliver($owner, $contact, $atom); $deliver_status = DFRN::deliver($owner, $contact, $atom);
$protocol = Model\ItemDeliveryData::LEGACY_DFRN; $protocol = Model\Post\DeliveryData::LEGACY_DFRN;
} }
Logger::info('DFRN Delivery', ['cmd' => $cmd, 'url' => $contact['url'], 'guid' => ($target_item['guid'] ?? '') ?: $target_item['id'], 'return' => $deliver_status]); Logger::info('DFRN Delivery', ['cmd' => $cmd, 'url' => $contact['url'], 'guid' => ($target_item['guid'] ?? '') ?: $target_item['id'], 'return' => $deliver_status]);
@ -390,7 +390,7 @@ class Delivery
Model\Contact::unmarkForArchival($contact); Model\Contact::unmarkForArchival($contact);
if (in_array($cmd, [Delivery::POST, Delivery::POKE])) { if (in_array($cmd, [Delivery::POST, Delivery::POKE])) {
Model\ItemDeliveryData::incrementQueueDone($target_item['id'], $protocol); Model\Post\DeliveryData::incrementQueueDone($target_item['uri-id'], $protocol);
} }
} else { } else {
// The message could not be delivered. We mark the contact as "dead" // The message could not be delivered. We mark the contact as "dead"
@ -398,7 +398,7 @@ class Delivery
Logger::info('Delivery failed: defer message', ['id' => ($target_item['guid'] ?? '') ?: $target_item['id']]); Logger::info('Delivery failed: defer message', ['id' => ($target_item['guid'] ?? '') ?: $target_item['id']]);
if (!Worker::defer() && in_array($cmd, [Delivery::POST, Delivery::POKE])) { if (!Worker::defer() && in_array($cmd, [Delivery::POST, Delivery::POKE])) {
Model\ItemDeliveryData::incrementQueueFailed($target_item['id']); Model\Post\DeliveryData::incrementQueueFailed($target_item['uri-id']);
} }
} }
} }
@ -475,7 +475,7 @@ class Delivery
Model\Contact::unmarkForArchival($contact); Model\Contact::unmarkForArchival($contact);
if (in_array($cmd, [Delivery::POST, Delivery::POKE])) { if (in_array($cmd, [Delivery::POST, Delivery::POKE])) {
Model\ItemDeliveryData::incrementQueueDone($target_item['id'], Model\ItemDeliveryData::DIASPORA); Model\Post\DeliveryData::incrementQueueDone($target_item['uri-id'], Model\Post\DeliveryData::DIASPORA);
} }
} else { } else {
// The message could not be delivered. We mark the contact as "dead" // The message could not be delivered. We mark the contact as "dead"
@ -490,10 +490,10 @@ class Delivery
Logger::info('Delivery failed: defer message', ['id' => ($target_item['guid'] ?? '') ?: $target_item['id']]); Logger::info('Delivery failed: defer message', ['id' => ($target_item['guid'] ?? '') ?: $target_item['id']]);
// defer message for redelivery // defer message for redelivery
if (!Worker::defer() && in_array($cmd, [Delivery::POST, Delivery::POKE])) { if (!Worker::defer() && in_array($cmd, [Delivery::POST, Delivery::POKE])) {
Model\ItemDeliveryData::incrementQueueFailed($target_item['id']); Model\Post\DeliveryData::incrementQueueFailed($target_item['uri-id']);
} }
} elseif (in_array($cmd, [Delivery::POST, Delivery::POKE])) { } elseif (in_array($cmd, [Delivery::POST, Delivery::POKE])) {
Model\ItemDeliveryData::incrementQueueFailed($target_item['id']); Model\Post\DeliveryData::incrementQueueFailed($target_item['uri-id']);
} }
} }
} }
@ -603,7 +603,7 @@ class Delivery
Email::send($addr, $subject, $headers, $target_item); Email::send($addr, $subject, $headers, $target_item);
Model\ItemDeliveryData::incrementQueueDone($target_item['id'], Model\ItemDeliveryData::MAIL); Model\Post\DeliveryData::incrementQueueDone($target_item['uri-id'], Model\Post\DeliveryData::MAIL);
Logger::info('Delivered via mail', ['guid' => $target_item['guid'], 'to' => $addr, 'subject' => $subject]); Logger::info('Delivered via mail', ['guid' => $target_item['guid'], 'to' => $addr, 'subject' => $subject]);
} }

View file

@ -32,7 +32,7 @@ use Friendica\Model\Contact;
use Friendica\Model\Conversation; use Friendica\Model\Conversation;
use Friendica\Model\Group; use Friendica\Model\Group;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Model\ItemDeliveryData; use Friendica\Model\Post;
use Friendica\Model\PushSubscriber; use Friendica\Model\PushSubscriber;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Network\Probe; use Friendica\Network\Probe;
@ -573,7 +573,7 @@ class Notifier
/// @TODO Redeliver/queue these items on failure, though there is no contact record /// @TODO Redeliver/queue these items on failure, though there is no contact record
$delivery_queue_count++; $delivery_queue_count++;
Salmon::slapper($owner, $url, $slap); Salmon::slapper($owner, $url, $slap);
ItemDeliveryData::incrementQueueDone($target_id, ItemDeliveryData::OSTATUS); Post\DeliveryData::incrementQueueDone($target_item['uri-id'], Post\DeliveryData::OSTATUS);
} }
} }
@ -595,11 +595,11 @@ class Notifier
// Workaround for pure connector posts // Workaround for pure connector posts
if (in_array($cmd, [Delivery::POST, Delivery::POKE])) { if (in_array($cmd, [Delivery::POST, Delivery::POKE])) {
if ($delivery_queue_count == 0) { if ($delivery_queue_count == 0) {
ItemDeliveryData::incrementQueueDone($target_item['id']); Post\DeliveryData::incrementQueueDone($target_item['uri-id']);
$delivery_queue_count = 1; $delivery_queue_count = 1;
} }
ItemDeliveryData::incrementQueueCount($target_item['id'], $delivery_queue_count); Post\DeliveryData::incrementQueueCount($target_item['uri-id'], $delivery_queue_count);
} }
} }

View file

@ -804,25 +804,6 @@ return [
"uri-id" => ["uri-id"] "uri-id" => ["uri-id"]
] ]
], ],
"item-delivery-data" => [
"comment" => "Delivery data for items",
"fields" => [
"iid" => ["type" => "int unsigned", "not null" => "1", "primary" => "1", "relation" => ["item" => "id"], "comment" => "Item id"],
"postopts" => ["type" => "text", "comment" => "External post connectors add their network name to this comma-separated string to identify that they should be delivered to these networks during delivery"],
"inform" => ["type" => "mediumtext", "comment" => "Additional receivers of the linked item"],
"queue_count" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Initial number of delivery recipients, used as item.delivery_queue_count"],
"queue_done" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of successful deliveries, used as item.delivery_queue_done"],
"queue_failed" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of unsuccessful deliveries, used as item.delivery_queue_failed"],
"activitypub" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of successful deliveries via ActivityPub"],
"dfrn" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of successful deliveries via DFRN"],
"legacy_dfrn" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of successful deliveries via legacy DFRN"],
"diaspora" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of successful deliveries via Diaspora"],
"ostatus" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of successful deliveries via OStatus"],
],
"indexes" => [
"PRIMARY" => ["iid"],
]
],
"item-uri" => [ "item-uri" => [
"comment" => "URI and GUID for items", "comment" => "URI and GUID for items",
"fields" => [ "fields" => [
@ -1306,6 +1287,25 @@ return [
"url" => ["url"] "url" => ["url"]
] ]
], ],
"post-delivery-data" => [
"comment" => "Delivery data for items",
"fields" => [
"uri-id" => ["type" => "int unsigned", "not null" => "1", "primary" => "1", "relation" => ["item-uri" => "id"], "comment" => "Id of the item-uri table entry that contains the item uri"],
"postopts" => ["type" => "text", "comment" => "External post connectors add their network name to this comma-separated string to identify that they should be delivered to these networks during delivery"],
"inform" => ["type" => "mediumtext", "comment" => "Additional receivers of the linked item"],
"queue_count" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Initial number of delivery recipients, used as item.delivery_queue_count"],
"queue_done" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of successful deliveries, used as item.delivery_queue_done"],
"queue_failed" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of unsuccessful deliveries, used as item.delivery_queue_failed"],
"activitypub" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of successful deliveries via ActivityPub"],
"dfrn" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of successful deliveries via DFRN"],
"legacy_dfrn" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of successful deliveries via legacy DFRN"],
"diaspora" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of successful deliveries via Diaspora"],
"ostatus" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of successful deliveries via OStatus"],
],
"indexes" => [
"PRIMARY" => ["uri-id"],
]
],
"post-tag" => [ "post-tag" => [
"comment" => "post relation to tags", "comment" => "post relation to tags",
"fields" => [ "fields" => [