- Logger::notice('Recursion level is too high, fetching is done by worker.', ['parent' => $activity['reply-to-id'], 'recursion-depth' => $recursion_depth]);
- Worker::add(PRIORITY_HIGH, 'FetchMissingActivity', $activity['reply-to-id'], $activity, '', Receiver::COMPLETION_AUTO);
- return [];
+ Logger::notice('Recursion level is too high.', ['parent' => $activity['reply-to-id'], 'recursion-depth' => $recursion_depth]);
+ $fetch_by_worker = true;
+ }
+
+ if ($fetch_by_worker && Queue::hasWorker($activity)) {
+ Logger::notice('There is already a worker task to fetch the post.', ['id' => $activity['id'], 'parent' => $activity['reply-to-id']]);
+ $fetch_by_worker = false;
+ if (!empty($conversation)) {
+ return [];
+ }
+ }
+
+ if ($fetch_by_worker) {
+ Logger::notice('Fetching is done by worker.', ['parent' => $activity['reply-to-id'], 'recursion-depth' => $recursion_depth]);
+ $activity['recursion-depth'] = 0;
+ $wid = Worker::add(PRIORITY_HIGH, 'FetchMissingActivity', $activity['reply-to-id'], $activity, '', Receiver::COMPLETION_AUTO);
+ Queue::setWorkerId($activity, $wid);
+ if (!empty($conversation)) {
+ return [];
+ }
+ } elseif (!empty($result)) {
+ if (($item['thr-parent'] != $result) && Post::exists(['uri' => $result])) {
+ $item['thr-parent'] = $result;
+ }