]> git.mxchange.org Git - friendica.git/commitdiff
Avoid loops at deletion / decoupling for relay posts
authorMichael <heluecht@pirati.ca>
Thu, 28 Jul 2022 05:29:47 +0000 (05:29 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 28 Jul 2022 05:29:47 +0000 (05:29 +0000)
src/Protocol/ActivityPub/Processor.php
src/Protocol/ActivityPub/Queue.php
src/Protocol/ActivityPub/Receiver.php
src/Protocol/ActivityPub/Transmitter.php

index 2025aba04ef83366aeae16b8f0c7ea7f530d25cf..421f2d4c0c36ba47bb63cdc9428260d6ba0393ab 100644 (file)
@@ -24,6 +24,7 @@ namespace Friendica\Protocol\ActivityPub;
 use Friendica\Content\Text\BBCode;
 use Friendica\Content\Text\HTML;
 use Friendica\Content\Text\Markdown;
+use Friendica\Core\Cache\Enum\Duration;
 use Friendica\Core\Logger;
 use Friendica\Core\Protocol;
 use Friendica\Core\System;
@@ -56,6 +57,7 @@ use Friendica\Worker\Delivery;
  */
 class Processor
 {
+       const CACHEKEY_FETCH_ACTIVITY = 'processor:fetchMissingActivity:';
        /**
         * Extracts the tag character (#, @, !) from mention links
         *
@@ -1218,15 +1220,23 @@ class Processor
                        $uid = 0;
                }
 
-               $object = ActivityPub::fetchContent($url, $uid);
-               if (empty($object)) {
-                       Logger::notice('Activity was not fetchable, aborting.', ['url' => $url, 'uid' => $uid]);
-                       return '';
-               }
+               $cachekey = self::CACHEKEY_FETCH_ACTIVITY . $url;
+               $object = DI::cache()->get($cachekey);
 
-               if (empty($object['id'])) {
-                       Logger::notice('Activity has got not id, aborting. ', ['url' => $url, 'object' => $object]);
-                       return '';
+               if (is_null($object)) {
+                       $object = ActivityPub::fetchContent($url, $uid);
+                       if (empty($object)) {
+                               Logger::notice('Activity was not fetchable, aborting.', ['url' => $url, 'uid' => $uid]);
+                               return '';
+                       }
+
+                       if (empty($object['id'])) {
+                               Logger::notice('Activity has got not id, aborting. ', ['url' => $url, 'object' => $object]);
+                               return '';
+                       }
+                       DI::cache()->set($cachekey, $object, Duration::FIVE_MINUTES);
+               } else {
+                       Logger::debug('Fetch from cache', ['url' => $url]);
                }
 
                $signer = [];
index 49d448bac1a39a95b01222bb3295a960f7e8e705..95a4cfa0d4557ecd5a34e33ef8ae5d413ac751dc 100644 (file)
@@ -126,14 +126,6 @@ class Queue
                        return;
                }
 
-               $children = DBA::select('inbox-entry', ['id'], ['in-reply-to-id' => $entry['object-id']]);
-               while ($child = DBA::fetch($children)) {
-                       if ($id == $child['id']) {
-                               continue;
-                       }
-                       self::deleteById($child['id']);
-               }
-               DBA::close($children);
                DBA::delete('inbox-entry', ['id' => $entry['id']]);
        }
 
index 0515b24e7d8516ccf11520c4144f201eebd4456e..af6eca61e8ff6a0041fdbbd872dd1d00bc327bf7 100644 (file)
@@ -208,13 +208,6 @@ class Receiver
                        Logger::notice('Relayed message had not been fetched', ['id' => $object_id, 'actor' => $actor]);
                        return;
                }
-
-               $item_id = Item::searchByLink($object_id);
-               if ($item_id) {
-                       Logger::info('Relayed message had been fetched and stored', ['id' => $object_id, 'item' => $item_id, 'actor' => $actor]);
-               } else {
-                       Logger::notice('Relayed message had not been stored', ['id' => $object_id, 'actor' => $actor]);
-               }
        }
 
        /**
@@ -599,9 +592,10 @@ class Receiver
                        return;
                }
 
-               if ($push) {
+               if (!empty($object_data['entry-id']) && ($push || ($activity['completion-mode'] == self::COMPLETION_RELAY))) {
                        // We delay by 5 seconds to allow to accumulate all receivers
                        $delayed = date(DateTimeFormat::MYSQL, time() + 5);
+                       Logger::debug('Initiate processing', ['id' => $object_data['entry-id'], 'uri' => $object_data['object_id']]);
                        Worker::add(['priority' => PRIORITY_HIGH, 'delayed' => $delayed], 'ProcessQueue', $object_data['entry-id']);
                        return;
                }
index 9bcf3128626bb9fb9568284447142a47e5907aa4..ddf495794650162a7f33f3552c5adb1c86f61866 100644 (file)
@@ -31,7 +31,6 @@ use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\APContact;
 use Friendica\Model\Contact;
-use Friendica\Model\Conversation;
 use Friendica\Model\GServer;
 use Friendica\Model\Item;
 use Friendica\Model\Photo;