From d8bf9c4601988216eb95d7a24288a440434454b0 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 18 Jul 2021 16:42:55 +0000 Subject: [PATCH] Prevent loop also when fetching the outbox --- src/Model/APContact.php | 23 +++++++++++++---------- src/Protocol/ActivityPub/Transmitter.php | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/Model/APContact.php b/src/Model/APContact.php index 1ae34a40a..e9500f85b 100644 --- a/src/Model/APContact.php +++ b/src/Model/APContact.php @@ -148,6 +148,19 @@ class APContact $url = $apcontact['url']; } + // Detect multiple fast repeating request to the same address + // See https://github.com/friendica/friendica/issues/9303 + $cachekey = 'apcontact:getByURL:' . $url; + $result = DI::cache()->get($cachekey); + if (!is_null($result)) { + Logger::notice('Multiple requests for the address', ['url' => $url, 'update' => $update, 'callstack' => System::callstack(20), 'result' => $result]); + if (!empty($fetched_contact)) { + return $fetched_contact; + } + } else { + DI::cache()->set($cachekey, System::callstack(20), Duration::FIVE_MINUTES); + } + $curlResult = HTTPSignature::fetchRaw($url); $failed = empty($curlResult) || empty($curlResult->getBody()) || (!$curlResult->isSuccess() && ($curlResult->getReturnCode() != 410)); @@ -171,16 +184,6 @@ class APContact return $fetched_contact; } - // Detect multiple fast repeating request to the same address - // See https://github.com/friendica/friendica/issues/9303 - $cachekey = 'apcontact:getByURL:' . $url; - $result = DI::cache()->get($cachekey); - if (!is_null($result)) { - Logger::notice('Multiple requests for the address', ['url' => $url, 'update' => $update, 'callstack' => System::callstack(20), 'result' => $result]); - } else { - DI::cache()->set($cachekey, System::callstack(20), Duration::FIVE_MINUTES); - } - $apcontact['url'] = $compacted['@id']; $apcontact['uuid'] = JsonLD::fetchElement($compacted, 'diaspora:guid', '@value'); $apcontact['type'] = str_replace('as:', '', JsonLD::fetchElement($compacted, '@type')); diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index a65f85542..c19dcf002 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -235,7 +235,7 @@ class Transmitter */ public static function getOutbox($owner, $page = null, $requester = '') { - $public_contact = Contact::getIdForURL($owner['url']); + $public_contact = Contact::getIdForURL($owner['url'], 0, false); $condition = ['uid' => 0, 'contact-id' => $public_contact, 'private' => [Item::PUBLIC, Item::UNLISTED]];