]> git.mxchange.org Git - friendica.git/commitdiff
Avoid to provess the same activity
authorMichael <heluecht@pirati.ca>
Thu, 4 Aug 2022 21:52:10 +0000 (21:52 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 4 Aug 2022 21:52:10 +0000 (21:52 +0000)
src/Protocol/ActivityPub/Processor.php
src/Protocol/ActivityPub/Queue.php

index 7270f7fc4b8e72bef85b388be2bdc7a899bba45f..92aa3b783334decb05b2aee759d66bd595d57f79 100644 (file)
@@ -59,6 +59,23 @@ class Processor
 {
        const CACHEKEY_FETCH_ACTIVITY = 'processor:fetchMissingActivity:';
        const CACHEKEY_JUST_FETCHED   = 'processor:isJustFetched:';
+
+       static $processed = [];
+
+       public static function addActivityId(string $id)
+       {
+               self::$processed[] = $id;
+               if (count(self::$processed) > 100) {
+                       self::$processed = array_slice(self::$processed, 1);
+               }
+               print_r(self::$processed);
+       }
+
+       public static function isProcessed(string $id): bool
+       {
+               return in_array($id, self::$processed);
+       }
+
        /**
         * Extracts the tag character (#, @, !) from mention links
         *
@@ -275,6 +292,13 @@ class Processor
         */
        public static function createItem(array $activity, bool $fetch_parents = true): array
        {
+               if (self::isProcessed($activity['id'])) {
+                       Logger::info('Id is already processed', ['id' => $activity['id']]);
+                       return [];
+               }
+
+               self::addActivityId($activity['id']);
+
                $item = [];
                $item['verb'] = Activity::POST;
                $item['thr-parent'] = $activity['reply-to-id'];
index 2fa95897c67f6cd0aeba351a06487d42c5cb9de0..df4236b5bdbdf97df0db57e50810124ff2af1b26 100644 (file)
@@ -22,6 +22,7 @@
 namespace Friendica\Protocol\ActivityPub;
 
 use Friendica\Core\Logger;
+use Friendica\Core\System;
 use Friendica\Database\Database;
 use Friendica\Database\DBA;
 use Friendica\DI;
@@ -199,7 +200,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']]);
+               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)]);
 
                $activity = json_decode($entry['activity'], true);
                $type     = $entry['type'];