From 3af55de978b8204123d91c89f37951754c3e2253 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 27 Jul 2022 20:03:28 +0000 Subject: [PATCH] Issue 11776 - process replies via a worker task --- src/Protocol/ActivityPub/Processor.php | 6 +++- src/Protocol/ActivityPub/Queue.php | 20 ++++++++++-- src/Worker/ProcessReplyByUri.php | 42 ++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 src/Worker/ProcessReplyByUri.php diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php index db8f28aa0..30f6627ba 100644 --- a/src/Protocol/ActivityPub/Processor.php +++ b/src/Protocol/ActivityPub/Processor.php @@ -980,7 +980,11 @@ class Processor if ($success) { Queue::remove($activity); - Queue::processReplyByUri($item['uri']); + + if (Queue::hasChildren($item['uri'])) { + //Queue::processReplyByUri($item['uri']); + Worker::add(PRIORITY_HIGH, 'ProcessReplyByUri', $item['uri']); + } } // Store send a follow request for every reshare - but only when the item had been stored diff --git a/src/Protocol/ActivityPub/Queue.php b/src/Protocol/ActivityPub/Queue.php index d47007eb1..b389626a3 100644 --- a/src/Protocol/ActivityPub/Queue.php +++ b/src/Protocol/ActivityPub/Queue.php @@ -25,7 +25,6 @@ use Friendica\Core\Logger; use Friendica\Database\Database; use Friendica\Database\DBA; use Friendica\DI; -use Friendica\Protocol\ActivityPub; use Friendica\Util\DateTimeFormat; use Friendica\Util\JsonLD; @@ -242,15 +241,30 @@ class Queue * Process all activities that are children of a given post url * * @param string $uri - * @return void + * @return int */ - public static function processReplyByUri(string $uri) + public static function processReplyByUri(string $uri): int { + $count = 0; $entries = DBA::select('inbox-entry', ['id'], ["`in-reply-to-id` = ? AND `object-id` != ?", $uri, $uri]); while ($entry = DBA::fetch($entries)) { + $count += 1; self::process($entry['id']); } DBA::close($entries); + return $count; + } + + /** + * Checks if there are children of the given uri + * + * @param string $uri + * + * @return bool + */ + public static function hasChildren(string $uri): bool + { + return DBA::exists('inbox-entry', ["`in-reply-to-id` = ? AND `object-id` != ?", $uri, $uri]); } /** diff --git a/src/Worker/ProcessReplyByUri.php b/src/Worker/ProcessReplyByUri.php new file mode 100644 index 000000000..000327b11 --- /dev/null +++ b/src/Worker/ProcessReplyByUri.php @@ -0,0 +1,42 @@ +. + * + */ + +namespace Friendica\Worker; + +use Friendica\Core\Logger; +use Friendica\Protocol\ActivityPub\Queue; + +class ProcessReplyByUri +{ + /** + * Process queued replies + * + * @param string $uri post url + * + * @return void + */ + public static function execute(string $uri) + { + Logger::info('Start processing queued replies', ['url' => $uri]); + $count = Queue::processReplyByUri($uri); + Logger::info('Successfully processed queued replies', ['count' => $count, 'url' => $uri]); + } +}