X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FAPContact.php;h=6a8e5b3ae1c78e39433c1d25543fab4a02718616;hb=deb6b7a7c3d62a42e2f71a3adf7ba3689e741f5a;hp=68bd80f037b70068c319c936c96c57641f4161fd;hpb=7b70eefbb636e48ec603f4cad366e0158c80e947;p=friendica.git diff --git a/src/Model/APContact.php b/src/Model/APContact.php index 68bd80f037..6a8e5b3ae1 100644 --- a/src/Model/APContact.php +++ b/src/Model/APContact.php @@ -22,17 +22,18 @@ namespace Friendica\Model; use Friendica\Content\Text\HTML; +use Friendica\Core\Cache\Duration; use Friendica\Core\Logger; +use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Network\Probe; use Friendica\Protocol\ActivityNamespace; use Friendica\Protocol\ActivityPub; use Friendica\Util\Crypto; -use Friendica\Util\Network; -use Friendica\Util\JsonLD; use Friendica\Util\DateTimeFormat; -use Friendica\Util\Strings; +use Friendica\Util\JsonLD; +use Friendica\Util\Network; class APContact { @@ -42,7 +43,7 @@ class APContact * @param string $addr Address * @return array webfinger data */ - public static function fetchWebfingerData(string $addr) + private static function fetchWebfingerData(string $addr) { $addr_parts = explode('@', $addr); if (count($addr_parts) != 2) { @@ -156,6 +157,16 @@ 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')); @@ -304,6 +315,10 @@ class APContact $apcontact['baseurl'] = null; } + if (empty($apcontact['subscribe'])) { + $apcontact['subscribe'] = null; + } + if (!empty($apcontact['baseurl']) && empty($fetched_contact['gsid'])) { $apcontact['gsid'] = GServer::getID($apcontact['baseurl']); } elseif (!empty($fetched_contact['gsid'])) { @@ -318,13 +333,18 @@ class APContact $apcontact['updated'] = DateTimeFormat::utcNow(); - DBA::update('apcontact', $apcontact, ['url' => $url], true); - // We delete the old entry when the URL is changed - if (($url != $apcontact['url']) && DBA::exists('apcontact', ['url' => $url]) && DBA::exists('apcontact', ['url' => $apcontact['url']])) { + if ($url != $apcontact['url']) { + Logger::info('Delete changed profile url', ['old' => $url, 'new' => $apcontact['url']]); DBA::delete('apcontact', ['url' => $url]); } + if (DBA::exists('apcontact', ['url' => $apcontact['url']])) { + DBA::update('apcontact', $apcontact, ['url' => $apcontact['url']]); + } else { + DBA::replace('apcontact', $apcontact); + } + Logger::info('Updated profile', ['url' => $url]); return $apcontact; @@ -347,7 +367,7 @@ class APContact if (!DBA::exists('inbox-status', ['url' => $url])) { $fields = array_merge($fields, ['url' => $url, 'created' => $now]); - DBA::insert('inbox-status', $fields); + DBA::replace('inbox-status', $fields); } else { DBA::update('inbox-status', $fields, ['url' => $url]); }