Disable server records before probe to avoid zombies

- Also disable exact match records to avoid http/https double record issues
- Address friendica/friendica-directory#105
This commit is contained in:
Hypolite Petovan 2024-04-29 23:51:52 -04:00
parent cfff03f6e2
commit d1933a1f74
2 changed files with 20 additions and 6 deletions

View file

@ -57,4 +57,13 @@ class Server extends \Friendica\Directory\Model
return null; return null;
} }
public function getByBaseUrl(string $polled_url): ?array
{
$polled_url = trim($polled_url, '/');
return $this->atlas->fetchOne('SELECT s.* FROM `server` s WHERE s.`base_url` = :base_url',
['base_url' => $polled_url]
);
}
} }

View file

@ -78,9 +78,18 @@ class Server
return 0; return 0;
} }
$server = $this->serverModel->getByUrlAlias($polled_url); // Disabling exact match first
if ($server = $this->serverModel->getByBaseUrl($polled_url)) {
$this->atlas->perform('UPDATE `server` SET `available` = 0 WHERE `id` = :server_id', ['server_id' => $server['id']]);
}
if ( // Disabling before probe to avoid zombie records
$server = $this->serverModel->getByUrlAlias($polled_url);
if ($server) {
$this->atlas->perform('UPDATE `server` SET `available` = 0 WHERE `id` = :server_id', ['server_id' => $server['id']]);
}
if (
$server $server
&& substr($polled_url, 0, 7) == 'http://' && substr($polled_url, 0, 7) == 'http://'
&& substr($server['base_url'], 0, 8) == 'https://' && substr($server['base_url'], 0, 8) == 'https://'
@ -89,10 +98,6 @@ class Server
return $server['id']; return $server['id'];
} }
if ($server) {
$this->atlas->perform('UPDATE `server` SET `available` = 0 WHERE `id` = :server_id', ['server_id' => $server['id']]);
}
$probe_result = $this->getProbeResult($polled_url); $probe_result = $this->getProbeResult($polled_url);
$parse_success = !empty($probe_result['data']['url']); $parse_success = !empty($probe_result['data']['url']);