From: Michael Date: Mon, 19 Dec 2022 19:41:04 +0000 (+0000) Subject: Fix delivery problems with "reachable" test X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=d39f4014e40289b46b598117197f60d9c2db034c;p=friendica.git Fix delivery problems with "reachable" test --- diff --git a/src/Model/GServer.php b/src/Model/GServer.php index ec7a4b080e..2fc37f35c3 100644 --- a/src/Model/GServer.php +++ b/src/Model/GServer.php @@ -167,31 +167,43 @@ class GServer /** * Checks if the given server is reachable * - * @param string $profile URL of the given profile - * @param string $server URL of the given server (If empty, taken from profile) - * @param string $network Network value that is used, when detection failed - * @param boolean $force Force an update. + * @param array $contact Contact that should be checked * * @return boolean 'true' if server seems vital */ - public static function reachable(string $profile, string $server = '', string $network = '', bool $force = false): bool + public static function reachable(array $contact): bool { - if ($server == '') { - $contact = Contact::getByURL($profile, null, ['baseurl', 'network']); - if (!empty($contact['baseurl'])) { - $server = $contact['baseurl']; - } elseif ($contact['network'] == Protocol::DIASPORA) { - $parts = parse_url($profile); - unset($parts['path']); - $server = (string)Uri::fromParts($parts); - } + if (!empty($contact['gsid'])) { + $gsid = $contact['gsid']; + } elseif (!empty($contact['baseurl'])) { + $server = $contact['baseurl']; + } elseif ($contact['network'] == Protocol::DIASPORA) { + $parts = parse_url($contact['url']); + unset($parts['path']); + $server = (string)Uri::fromParts($parts); + } else { + return true; } - if ($server == '') { - return true; + if (!empty($gsid)) { + $condition = ['id' => $gsid]; + } else { + $condition = ['nurl' => Strings::normaliseLink($server)]; + } + + $gserver = DBA::selectFirst('gserver', ['url', 'next_contact', 'failed'], $condition); + if (empty($gserver)) { + $reachable = true; + } else { + $reachable = !$gserver['failed']; + $server = $gserver['url']; + } + + if (!empty($server) && (empty($gserver) || strtotime($gserver['next_contact']) < time())) { + Worker::add(Worker::PRIORITY_LOW, 'UpdateGServer', $server, false); } - return self::check($server, $network, $force); + return $reachable; } /** diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index c820873cff..7bf3696a53 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -100,7 +100,7 @@ class Notifier $uid = $target_id; $condition = ['uid' => $target_id, 'self' => false, 'network' => [Protocol::DFRN, Protocol::DIASPORA]]; - $delivery_contacts_stmt = DBA::select('contact', ['id', 'url', 'addr', 'network', 'protocol', 'baseurl', 'batch'], $condition); + $delivery_contacts_stmt = DBA::select('contact', ['id', 'url', 'addr', 'network', 'protocol', 'baseurl', 'gsid', 'batch'], $condition); } else { $post = Post::selectFirst(['id'], ['uri-id' => $post_uriid, 'uid' => $sender_uid]); if (!DBA::isResult($post)) { @@ -426,7 +426,7 @@ class Notifier if (!empty($networks)) { $condition['network'] = $networks; } - $delivery_contacts_stmt = DBA::select('contact', ['id', 'addr', 'url', 'network', 'protocol', 'baseurl', 'batch'], $condition); + $delivery_contacts_stmt = DBA::select('contact', ['id', 'addr', 'url', 'network', 'protocol', 'baseurl', 'gsid', 'batch'], $condition); } $conversants = []; @@ -438,7 +438,7 @@ class Notifier if ($diaspora_delivery && !$unlisted) { $batch_delivery = true; - $participants = DBA::selectToArray('contact', ['batch', 'network', 'protocol', 'baseurl', 'id', 'url', 'name'], + $participants = DBA::selectToArray('contact', ['batch', 'network', 'protocol', 'baseurl', 'gsid', 'id', 'url', 'name'], ["`network` = ? AND `batch` != '' AND `uid` = ? AND `rel` != ? AND NOT `blocked` AND NOT `pending` AND NOT `archive`", Protocol::DIASPORA, $owner['uid'], Contact::SHARING], ['group_by' => ['batch', 'network', 'protocol']]); @@ -450,7 +450,7 @@ class Notifier $condition = ['network' => Protocol::DFRN, 'uid' => $owner['uid'], 'blocked' => false, 'pending' => false, 'archive' => false, 'rel' => [Contact::FOLLOWER, Contact::FRIEND]]; - $contacts = DBA::selectToArray('contact', ['id', 'url', 'addr', 'name', 'network', 'protocol', 'baseurl'], $condition); + $contacts = DBA::selectToArray('contact', ['id', 'url', 'addr', 'name', 'network', 'protocol', 'baseurl', 'gsid'], $condition); $conversants = array_merge($contacts, $participants); @@ -564,7 +564,7 @@ class Notifier continue; } - if (!GServer::reachable($contact['url'], $contact['baseurl'], $contact['network'])) { + if (!GServer::reachable($contact)) { Logger::info('Server is not reachable', ['id' => $post_uriid, 'uid' => $sender_uid, 'contact' => $contact]); continue; }