We now store the receivers as well
This commit is contained in:
parent
201610dfe6
commit
a662245c74
6 changed files with 34 additions and 28 deletions
|
@ -1127,6 +1127,7 @@ CREATE TABLE IF NOT EXISTS `post-delivery` (
|
||||||
`created` datetime DEFAULT '0001-01-01 00:00:00' COMMENT '',
|
`created` datetime DEFAULT '0001-01-01 00:00:00' COMMENT '',
|
||||||
`command` varbinary(32) COMMENT '',
|
`command` varbinary(32) COMMENT '',
|
||||||
`failed` tinyint DEFAULT 0 COMMENT 'Number of times the delivery has failed',
|
`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`),
|
PRIMARY KEY(`uri-id`,`inbox-id`),
|
||||||
INDEX `inbox-id_created` (`inbox-id`,`created`),
|
INDEX `inbox-id_created` (`inbox-id`,`created`),
|
||||||
INDEX `uid` (`uid`),
|
INDEX `uid` (`uid`),
|
||||||
|
|
|
@ -6,14 +6,15 @@ Delivery data for posts for the batch processing
|
||||||
Fields
|
Fields
|
||||||
------
|
------
|
||||||
|
|
||||||
| Field | Description | Type | Null | Key | Default | Extra |
|
| 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 | |
|
| 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 | |
|
| inbox-id | Item-uri id of inbox url | int unsigned | NO | PRI | NULL | |
|
||||||
| uid | Delivering user | mediumint unsigned | YES | | NULL | |
|
| uid | Delivering user | mediumint unsigned | YES | | NULL | |
|
||||||
| created | | datetime | YES | | 0001-01-01 00:00:00 | |
|
| created | | datetime | YES | | 0001-01-01 00:00:00 | |
|
||||||
| command | | varbinary(32) | YES | | NULL | |
|
| command | | varbinary(32) | YES | | NULL | |
|
||||||
| failed | Number of times the delivery has failed | tinyint | YES | | 0 | |
|
| failed | Number of times the delivery has failed | tinyint | YES | | 0 | |
|
||||||
|
| receivers | JSON encoded array with the receiving contacts | mediumtext | YES | | NULL | |
|
||||||
|
|
||||||
Indexes
|
Indexes
|
||||||
------------
|
------------
|
||||||
|
|
|
@ -35,14 +35,16 @@ class Delivery
|
||||||
* @param integer $uri_id
|
* @param integer $uri_id
|
||||||
* @param string $inbox
|
* @param string $inbox
|
||||||
* @param string $created
|
* @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)) {
|
if (empty($uri_id)) {
|
||||||
throw new BadMethodCallException('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);
|
DBA::insert('post-delivery', $fields, Database::INSERT_IGNORE);
|
||||||
}
|
}
|
||||||
|
@ -81,6 +83,18 @@ class Delivery
|
||||||
|
|
||||||
public static function selectForInbox(string $inbox)
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,6 @@ use Friendica\Core\Logger;
|
||||||
use Friendica\Core\Worker;
|
use Friendica\Core\Worker;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
use Friendica\Model\GServer;
|
use Friendica\Model\GServer;
|
||||||
use Friendica\Model\Item;
|
|
||||||
use Friendica\Model\Post;
|
use Friendica\Model\Post;
|
||||||
use Friendica\Protocol\ActivityPub;
|
use Friendica\Protocol\ActivityPub;
|
||||||
use Friendica\Util\HTTPSignature;
|
use Friendica\Util\HTTPSignature;
|
||||||
|
@ -93,7 +92,7 @@ class APDelivery
|
||||||
$posts = Post\Delivery::selectForInbox($inbox);
|
$posts = Post\Delivery::selectForInbox($inbox);
|
||||||
|
|
||||||
foreach ($posts as $post) {
|
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'];
|
$uri_ids[] = $post['uri-id'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,22 +105,12 @@ class APDelivery
|
||||||
{
|
{
|
||||||
if (empty($item_id) && !empty($uri_id) && !empty($uid)) {
|
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 = Post::selectFirst(['id', 'parent', 'origin'], ['uri-id' => $uri_id, 'uid' => [$uid, 0]], ['order' => ['uid' => true]]);
|
||||||
$item_id = $item['id'] ?? 0;
|
if (empty($item['id'])) {
|
||||||
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)) {
|
|
||||||
Logger::debug('Item not found, removing delivery', ['uri-id' => $uri_id, 'uid' => $uid, 'cmd' => $cmd, 'inbox' => $inbox]);
|
Logger::debug('Item not found, removing delivery', ['uri-id' => $uri_id, 'uid' => $uid, 'cmd' => $cmd, 'inbox' => $inbox]);
|
||||||
Post\Delivery::remove($uri_id, $inbox);
|
Post\Delivery::remove($uri_id, $inbox);
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
$item_id = $item['id'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -788,7 +788,7 @@ class Notifier
|
||||||
|
|
||||||
if (DI::config()->get('system', 'bulk_delivery')) {
|
if (DI::config()->get('system', 'bulk_delivery')) {
|
||||||
$delivery_queue_count++;
|
$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);
|
Worker::add(PRIORITY_HIGH, 'APDelivery', '', 0, $inbox, 0);
|
||||||
} else {
|
} else {
|
||||||
if (Worker::add(['priority' => $priority, 'created' => $created, 'dont_fork' => true],
|
if (Worker::add(['priority' => $priority, 'created' => $created, 'dont_fork' => true],
|
||||||
|
@ -804,7 +804,7 @@ class Notifier
|
||||||
|
|
||||||
if (DI::config()->get('system', 'bulk_delivery')) {
|
if (DI::config()->get('system', 'bulk_delivery')) {
|
||||||
$delivery_queue_count++;
|
$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);
|
Worker::add(PRIORITY_MEDIUM, 'APDelivery', '', 0, $inbox, 0);
|
||||||
} else {
|
} else {
|
||||||
if (Worker::add(['priority' => $priority, 'dont_fork' => true], 'APDelivery', $cmd, $target_item['id'], $inbox, $uid, [], $target_item['uri-id'])) {
|
if (Worker::add(['priority' => $priority, 'dont_fork' => true], 'APDelivery', $cmd, $target_item['id'], $inbox, $uid, [], $target_item['uri-id'])) {
|
||||||
|
|
|
@ -1166,6 +1166,7 @@ return [
|
||||||
"created" => ["type" => "datetime", "default" => DBA::NULL_DATETIME, "comment" => ""],
|
"created" => ["type" => "datetime", "default" => DBA::NULL_DATETIME, "comment" => ""],
|
||||||
"command" => ["type" => "varbinary(32)", "comment" => ""],
|
"command" => ["type" => "varbinary(32)", "comment" => ""],
|
||||||
"failed" => ["type" => "tinyint", "default" => 0, "comment" => "Number of times the delivery has failed"],
|
"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" => [
|
"indexes" => [
|
||||||
"PRIMARY" => ["uri-id", "inbox-id"],
|
"PRIMARY" => ["uri-id", "inbox-id"],
|
||||||
|
|
Loading…
Reference in a new issue