]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/ActivityPub/Queue.php
Merge pull request #13724 from Raroun/Fix-for-Issue-#13637---Photo-caption-prevents...
[friendica.git] / src / Protocol / ActivityPub / Queue.php
index a95226d10d81783d5d1874d85f7e617eb669ceca..3046c24580d57c3c40daaae483c50d7e619345df 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2022, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -22,7 +22,7 @@
 namespace Friendica\Protocol\ActivityPub;
 
 use Friendica\Core\Logger;
-use Friendica\Core\System;
+use Friendica\Core\Worker;
 use Friendica\Database\Database;
 use Friendica\Database\DBA;
 use Friendica\DI;
@@ -214,7 +214,7 @@ class Queue
                        }
                }
 
-               Logger::debug('Processing queue entry', ['id' => $entry['id'], 'type' => $entry['type'], 'object-type' => $entry['object-type'], 'uri' => $entry['object-id'], 'in-reply-to' => $entry['in-reply-to-id'], 'callstack' => System::callstack(20)]);
+               Logger::debug('Processing queue entry', ['id' => $entry['id'], 'type' => $entry['type'], 'object-type' => $entry['object-type'], 'uri' => $entry['object-id'], 'in-reply-to' => $entry['in-reply-to-id']]);
 
                $activity = json_decode($entry['activity'], true);
                $type     = $entry['type'];
@@ -236,7 +236,7 @@ class Queue
                }
                DBA::close($receivers);
 
-               if (!Receiver::routeActivities($activity, $type, $push, $fetch_parents)) {
+               if (!Receiver::routeActivities($activity, $type, $push, $fetch_parents, $activity['receiver'][0] ?? 0)) {
                        self::remove($activity);
                }
 
@@ -252,12 +252,7 @@ class Queue
        {
                $entries = DBA::select('inbox-entry', ['id', 'type', 'object-type', 'object-id', 'in-reply-to-id'], ["`trust` AND `wid` IS NULL"], ['order' => ['id' => true]]);
                while ($entry = DBA::fetch($entries)) {
-                       // Don't process entries of items that are answer to non existing posts
-                       if (!empty($entry['in-reply-to-id']) && !Post::exists(['uri' => $entry['in-reply-to-id']])) {
-                               continue;
-                       }
-                       // We don't need to process entries that depend on already existing entries.
-                       if (!empty($entry['in-reply-to-id']) && DBA::exists('inbox-entry', ["`id` != ? AND `object-id` = ?", $entry['id'], $entry['in-reply-to-id']])) {
+                       if (!self::isProcessable($entry['id'])) {
                                continue;
                        }
                        Logger::debug('Process leftover entry', $entry);
@@ -273,6 +268,10 @@ class Queue
                        return false;
                }
 
+               if (($entry['type'] == 'as:Follow') && ($entry['object-type'] == 'as:Note')) {
+                       return true;
+               }
+
                if (!empty($entry['object-id']) && Post::exists(['uri' => $entry['object-id']])) {
                        // The object already exists, so processing can be done
                        return true;
@@ -286,9 +285,25 @@ class Queue
                        }
                }
 
-               if (!empty($entry['object-id']) && !empty($entry['in-reply-to-id']) && ($entry['object-id'] != $entry['in-reply-to-id']) && DBA::exists('inbox-entry', ['object-id' => $entry['in-reply-to-id']])) {
-                       // This entry belongs to some other entry that should be processed first
-                       return false;
+               if (!empty($entry['object-id']) && !empty($entry['in-reply-to-id']) && ($entry['object-id'] != $entry['in-reply-to-id'])) {
+                       if (DBA::exists('inbox-entry', ['object-id' => $entry['in-reply-to-id']])) {
+                               // This entry belongs to some other entry that should be processed first
+                               return false;
+                       }
+                       if (!Post::exists(['uri' => $entry['in-reply-to-id']])) {
+                               // This entry belongs to some other entry that need to be fetched first
+                               if (Fetch::hasWorker($entry['in-reply-to-id'])) {
+                                       Logger::debug('Fetching of the activity is already queued', ['id' => $entry['activity-id'], 'reply-to-id' => $entry['in-reply-to-id']]);
+                                       return false;
+                               }
+                               Fetch::add($entry['in-reply-to-id']);
+                               $activity = json_decode($entry['activity'], true);
+                               $activity['recursion-depth'] = 0;
+                               $wid = Worker::add(Worker::PRIORITY_HIGH, 'FetchMissingActivity', $entry['in-reply-to-id'], $activity, '', Receiver::COMPLETION_ASYNC);
+                               Fetch::setWorkerId($entry['in-reply-to-id'], $wid);
+                               Logger::debug('Fetch missing activity', ['wid' => $wid, 'id' => $entry['activity-id'], 'reply-to-id' => $entry['in-reply-to-id']]);
+                               return false;
+                       }
                }
 
                return true;
@@ -312,7 +327,7 @@ class Queue
                // Optimizing this table only last seconds
                if (DI::config()->get('system', 'optimize_tables')) {
                        Logger::info('Optimize start');
-                       DBA::e("OPTIMIZE TABLE `inbox-entry`");
+                       DBA::optimizeTable('inbox-entry');
                        Logger::info('Optimize end');
                }
        }