Don't add contacts when not needed

This commit is contained in:
Michael 2020-01-01 17:54:36 +00:00
parent 6c2d13403e
commit 73b82d1455
6 changed files with 51 additions and 18 deletions

View file

@ -277,21 +277,29 @@ class Contact
*/
public static function getBasepath($url, $dont_update = false)
{
$contact = DBA::selectFirst('contact', ['baseurl'], ['uid' => 0, 'nurl' => Strings::normaliseLink($url)]);
$contact = DBA::selectFirst('contact', ['id', 'baseurl'], ['uid' => 0, 'nurl' => Strings::normaliseLink($url)]);
if (!DBA::isResult($contact)) {
return '';
}
if (!empty($contact['baseurl'])) {
return $contact['baseurl'];
} elseif ($dont_update) {
return '';
}
self::updateFromProbeByURL($url, true);
// Update the existing contact
self::updateFromProbe($contact['id'], '', true);
$contact = DBA::selectFirst('contact', ['baseurl'], ['uid' => 0, 'nurl' => Strings::normaliseLink($url)]);
if (!empty($contact['baseurl'])) {
return $contact['baseurl'];
// And fetch the result
$contact = DBA::selectFirst('contact', ['baseurl'], ['id' => $contact['id']]);
if (empty($contact['baseurl'])) {
Logger::info('No baseurl for contact', ['url' => $url]);
return '';
}
return '';
Logger::info('Found baseurl for contact', ['url' => $url, 'baseurl' => $contact['baseurl']]);
return $contact['baseurl'];
}
/**

View file

@ -216,7 +216,7 @@ class GContact
if (empty($gcontact['server_url'])) {
// We check the server url to be sure that it is a real one
$server_url = Contact::getBasepath($gcontact['url']);
$server_url = self::getBasepath($gcontact['url']);
// We are now sure that it is a correct URL. So we use it in the future
if ($server_url != '') {
@ -1128,6 +1128,38 @@ class GContact
self::update($gcontact);
}
/**
* @brief Get the basepath for a given contact link
*
* @param string $url The gcontact link
*
* @return string basepath
* @return boolean $dont_update Don't update the contact
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
public static function getBasepath($url, $dont_update = false)
{
$gcontact = DBA::selectFirst('gcontact', ['server_url'], ['nurl' => Strings::normaliseLink($url)]);
if (!empty($gcontact['server_url'])) {
return $gcontact['server_url'];
} elseif ($dont_update) {
return '';
}
self::updateFromProbe($url, true);
// Fetch the result
$gcontact = DBA::selectFirst('gcontact', ['server_url'], ['nurl' => Strings::normaliseLink($url)]);
if (empty($gcontact['server_url'])) {
Logger::info('No baseurl for gcontact', ['url' => $url]);
return '';
}
Logger::info('Found baseurl for gcontact', ['url' => $url, 'baseurl' => $gcontact['server_url']]);
return $gcontact['server_url'];
}
/**
* @brief Fetches users of given GNU Social server
*

View file

@ -44,7 +44,7 @@ class GServer
public static function reachable(string $profile, string $server = '', string $network = '', bool $force = false)
{
if ($server == '') {
$server = Contact::getBasepath($profile);
$server = GContact::getBasepath($profile);
}
if ($server == '') {