]> git.mxchange.org Git - friendica.git/commitdiff
We now store the receivers as well
authorMichael <heluecht@pirati.ca>
Fri, 13 May 2022 05:52:05 +0000 (05:52 +0000)
committerMichael <heluecht@pirati.ca>
Fri, 13 May 2022 05:52:05 +0000 (05:52 +0000)
database.sql
doc/database/db_post-delivery.md
src/Model/Post/Delivery.php
src/Worker/APDelivery.php
src/Worker/Notifier.php
static/dbstructure.config.php

index 1508f358dc071046bf01410dcea8da338a395c4b..d13a3330c2b3a92c85d4118aff33321b9dbe7977 100644 (file)
@@ -1127,6 +1127,7 @@ CREATE TABLE IF NOT EXISTS `post-delivery` (
        `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',
+       `receivers` mediumtext COMMENT 'JSON encoded array with the receiving contacts',
         PRIMARY KEY(`uri-id`,`inbox-id`),
         INDEX `inbox-id_created` (`inbox-id`,`created`),
         INDEX `uid` (`uid`),
index 8b149b57159fed955ca90f50a637e5d6b0dbc0c1..2a766eea56f31b93a697df17e70f389a40d2522b 100644 (file)
@@ -6,14 +6,15 @@ Delivery data for posts for the batch processing
 Fields
 ------
 
-| Field    | Description                                               | Type               | Null | Key | Default             | Extra |
-| -------- | --------------------------------------------------------- | ------------------ | ---- | --- | ------------------- | ----- |
-| uri-id   | Id of the item-uri table entry that contains the item uri | int unsigned       | NO   | PRI | NULL                |       |
-| inbox-id | Item-uri id of inbox url                                  | int unsigned       | NO   | PRI | NULL                |       |
-| 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                   |       |
+| Field     | Description                                               | Type               | Null | Key | Default             | Extra |
+| --------- | --------------------------------------------------------- | ------------------ | ---- | --- | ------------------- | ----- |
+| uri-id    | Id of the item-uri table entry that contains the item uri | int unsigned       | NO   | PRI | NULL                |       |
+| inbox-id  | Item-uri id of inbox url                                  | int unsigned       | NO   | PRI | NULL                |       |
+| 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                   |       |
+| receivers | JSON encoded array with the receiving contacts            | mediumtext         | YES  |     | NULL                |       |
 
 Indexes
 ------------
index 8d19f8c941136c319894e9dcfd96472a884f7e90..52c1bf8e0ee979c9d29c3f0fd9af65dcd8dd2906 100644 (file)
@@ -35,14 +35,16 @@ class Delivery
         * @param integer $uri_id
         * @param string  $inbox
         * @param string  $created
+        * @param array   %receivers
         */
-       public static function add(int $uri_id, int $uid, string $inbox, string $created, string $command)
+       public static function add(int $uri_id, int $uid, string $inbox, string $created, string $command, array $receivers)
        {
                if (empty($uri_id)) {
                        throw new BadMethodCallException('Empty URI_id');
                }
 
-               $fields = ['uri-id' => $uri_id, 'uid' => $uid, 'inbox-id' => ItemURI::getIdByURI($inbox), 'created' => $created, 'command' => $command];
+               $fields = ['uri-id' => $uri_id, 'uid' => $uid, 'inbox-id' => ItemURI::getIdByURI($inbox),
+                       'created' => $created, 'command' => $command, 'receivers' => json_encode($receivers)];
 
                DBA::insert('post-delivery', $fields, Database::INSERT_IGNORE);
        }
@@ -81,6 +83,18 @@ class Delivery
 
        public static function selectForInbox(string $inbox)
        {
-               return DBA::selectToArray('post-delivery', [], ['inbox-id' => ItemURI::getIdByURI($inbox)], ['order' => ['created']]);
+               $rows = DBA::select('post-delivery', [], ['inbox-id' => ItemURI::getIdByURI($inbox)], ['order' => ['created']]);
+               $deliveries = [];
+               while ($row = DBA::fetch($rows)) {
+                       if (!empty($row['receivers'])) {
+                               $row['receivers'] = json_decode($row['receivers'], true);
+                       } else {
+                               $row['receivers'] = [];
+                       }
+                       $deliveries[] = $row;
+               }
+               DBA::close($rows);
+
+               return $deliveries;
        }
 }
index 641f27fce42afabf063e3dd132cd779b5c1decbb..6995b0edf117333b0cbaf15697e2369032e9814e 100644 (file)
@@ -25,7 +25,6 @@ use Friendica\Core\Logger;
 use Friendica\Core\Worker;
 use Friendica\Model\Contact;
 use Friendica\Model\GServer;
-use Friendica\Model\Item;
 use Friendica\Model\Post;
 use Friendica\Protocol\ActivityPub;
 use Friendica\Util\HTTPSignature;
@@ -93,7 +92,7 @@ class APDelivery
                $posts   = Post\Delivery::selectForInbox($inbox);
 
                foreach ($posts as $post) {
-                       if (!self::deliverToInbox($post['command'], 0, $inbox, $post['uid'], [], $post['uri-id'])) {
+                       if (!self::deliverToInbox($post['command'], 0, $inbox, $post['uid'], $post['receivers'], $post['uri-id'])) {
                                $uri_ids[] = $post['uri-id'];
                        }
                }
@@ -106,22 +105,12 @@ class APDelivery
        {
                if (empty($item_id) && !empty($uri_id) && !empty($uid)) {
                        $item = Post::selectFirst(['id', 'parent', 'origin'], ['uri-id' => $uri_id, 'uid' => [$uid, 0]], ['order' => ['uid' => true]]);
-                       $item_id = $item['id'] ?? 0;
-                       if (empty($receivers) && !empty($item)) {
-                               $parent = Post::selectFirst(Item::DELIVER_FIELDLIST, ['id' => $item['parent']]);
-
-                               $inboxes = ActivityPub\Transmitter::fetchTargetInboxes($parent, $uid);
-                               $receivers = $inboxes[$inbox] ?? [];
-
-                               // When we haven't fetched the receiver list, it can be a personal inbox
-                               if (empty($receivers)) {
-                                       $inboxes = ActivityPub\Transmitter::fetchTargetInboxes($parent, $uid, true);
-                                       $receivers = $inboxes[$inbox] ?? [];
-                               }
-                       } elseif (empty($item_id)) {
+                       if (empty($item['id'])) {
                                Logger::debug('Item not found, removing delivery', ['uri-id' => $uri_id, 'uid' => $uid, 'cmd' => $cmd, 'inbox' => $inbox]);
                                Post\Delivery::remove($uri_id, $inbox);
                                return true;
+                       } else {
+                               $item_id = $item['id'];
                        }
                }
 
index 66c3cadbd1473b75bf50642a896c377df79e8198..e248c944dd39d7faedf94f177aacef3e5e1d96b3 100644 (file)
@@ -788,7 +788,7 @@ class Notifier
 
                        if (DI::config()->get('system', 'bulk_delivery')) {
                                $delivery_queue_count++;
-                               Post\Delivery::add($target_item['uri-id'], $uid, $inbox, $target_item['created'], $cmd);
+                               Post\Delivery::add($target_item['uri-id'], $uid, $inbox, $target_item['created'], $cmd, $receivers);
                                Worker::add(PRIORITY_HIGH, 'APDelivery', '', 0, $inbox, 0);
                        } else {
                                if (Worker::add(['priority' => $priority, 'created' => $created, 'dont_fork' => true],
@@ -804,7 +804,7 @@ class Notifier
 
                        if (DI::config()->get('system', 'bulk_delivery')) {
                                $delivery_queue_count++;
-                               Post\Delivery::add($target_item['uri-id'], $uid, $inbox, $target_item['created'], $cmd);
+                               Post\Delivery::add($target_item['uri-id'], $uid, $inbox, $target_item['created'], $cmd, []);
                                Worker::add(PRIORITY_MEDIUM, 'APDelivery', '', 0, $inbox, 0);
                        } else {
                                if (Worker::add(['priority' => $priority, 'dont_fork' => true], 'APDelivery', $cmd, $target_item['id'], $inbox, $uid, [], $target_item['uri-id'])) {
index 101e3da343a407d06b3ed29fd92e6b3cd5425484..44b2fc1f80fa5dff06e35e0799aab91dd25fe983 100644 (file)
@@ -1166,6 +1166,7 @@ return [
                        "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"],
+                       "receivers" => ["type" => "mediumtext", "comment" => "JSON encoded array with the receiving contacts"],
                ],
                "indexes" => [
                        "PRIMARY" => ["uri-id", "inbox-id"],