Merge pull request #13674 from annando/server-discovery

Improved control about the contact/server updates
This commit is contained in:
Hypolite Petovan 2023-11-27 15:20:07 -05:00 committed by GitHub
commit de807e6378
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 369 additions and 328 deletions

View File

@ -2373,6 +2373,10 @@ class GServer
*/
public static function discover()
{
if (!DI::config('system', 'discover_servers')) {
return;
}
// Update the server list
self::discoverFederation();
@ -2380,10 +2384,6 @@ class GServer
$requery_days = intval(DI::config()->get('system', 'poco_requery_days'));
if ($requery_days == 0) {
$requery_days = 7;
}
$last_update = date('c', time() - (60 * 60 * 24 * $requery_days));
$gservers = DBA::select('gserver', ['id', 'url', 'nurl', 'network', 'poco', 'directory-type'],

View File

@ -111,6 +111,7 @@ class Site extends BaseAdmin
$min_memory = (!empty($_POST['min_memory']) ? intval(trim($_POST['min_memory'])) : 0);
$optimize_tables = (!empty($_POST['optimize_tables']) ? intval(trim($_POST['optimize_tables'])) : false);
$contact_discovery = (!empty($_POST['contact_discovery']) ? intval(trim($_POST['contact_discovery'])) : Contact\Relation::DISCOVERY_NONE);
$update_active_contacts = (!empty($_POST['update_active_contacts']) ? intval(trim($_POST['update_active_contacts'])) : false);
$synchronize_directory = (!empty($_POST['synchronize_directory']) ? intval(trim($_POST['synchronize_directory'])) : false);
$poco_requery_days = (!empty($_POST['poco_requery_days']) ? intval(trim($_POST['poco_requery_days'])) : 7);
$poco_discovery = (!empty($_POST['poco_discovery']) ? intval(trim($_POST['poco_discovery'])) : false);
@ -156,15 +157,16 @@ class Site extends BaseAdmin
$diaspora_enabled = false;
}
$transactionConfig->set('system', 'maxloadavg' , $maxloadavg);
$transactionConfig->set('system', 'min_memory' , $min_memory);
$transactionConfig->set('system', 'optimize_tables' , $optimize_tables);
$transactionConfig->set('system', 'contact_discovery' , $contact_discovery);
$transactionConfig->set('system', 'synchronize_directory' , $synchronize_directory);
$transactionConfig->set('system', 'poco_requery_days' , $poco_requery_days);
$transactionConfig->set('system', 'poco_discovery' , $poco_discovery);
$transactionConfig->set('system', 'poco_local_search' , $poco_local_search);
$transactionConfig->set('system', 'nodeinfo' , $nodeinfo);
$transactionConfig->set('system', 'maxloadavg' , $maxloadavg);
$transactionConfig->set('system', 'min_memory' , $min_memory);
$transactionConfig->set('system', 'optimize_tables' , $optimize_tables);
$transactionConfig->set('system', 'contact_discovery' , $contact_discovery);
$transactionConfig->set('system', 'update_active_contacts' , $update_active_contacts);
$transactionConfig->set('system', 'synchronize_directory' , $synchronize_directory);
$transactionConfig->set('system', 'poco_requery_days' , $poco_requery_days);
$transactionConfig->set('system', 'poco_discovery' , $poco_discovery);
$transactionConfig->set('system', 'poco_local_search' , $poco_local_search);
$transactionConfig->set('system', 'nodeinfo' , $nodeinfo);
if (DI::config()->isWritable('config', 'sitename')) {
$transactionConfig->set('config', 'sitename', $sitename);
}
@ -486,10 +488,11 @@ class Site extends BaseAdmin
'<li>' . DI::l10n()->t('Local contacts - contacts of our local contacts are discovered for their followers/followings.') . '</li>' .
'<li>' . DI::l10n()->t('Interactors - contacts of our local contacts and contacts who interacted on locally visible postings are discovered for their followers/followings.') . '</li></ul>',
$discovery_choices],
'$update_active_contacts' => ['update_active_contacts', DI::l10n()->t('Only update contacts/servers with local data'), DI::config()->get('system', 'update_active_contacts'), DI::l10n()->t('If enabled, the system will only look for changes in contacts and servers that engaged on this system by either being in a contact list of a user or when posts or comments exists from the contact on this system.')],
'$synchronize_directory' => ['synchronize_directory', DI::l10n()->t('Synchronize the contacts with the directory server'), DI::config()->get('system', 'synchronize_directory'), DI::l10n()->t('if enabled, the system will check periodically for new contacts on the defined directory server.')],
'$poco_requery_days' => ['poco_requery_days', DI::l10n()->t('Days between requery'), DI::config()->get('system', 'poco_requery_days'), DI::l10n()->t('Number of days after which a server is requeried for his contacts.')],
'$poco_discovery' => ['poco_discovery', DI::l10n()->t('Discover contacts from other servers'), DI::config()->get('system', 'poco_discovery'), DI::l10n()->t('Periodically query other servers for contacts. The system queries Friendica, Mastodon and Hubzilla servers.')],
'$poco_discovery' => ['poco_discovery', DI::l10n()->t('Discover contacts from other servers'), DI::config()->get('system', 'poco_discovery'), DI::l10n()->t('Periodically query other servers for contacts and servers that they know of. The system queries Friendica, Mastodon and Hubzilla servers. Keep it deactivated on small machines to decrease the database size and load.')],
'$poco_requery_days' => ['poco_requery_days', DI::l10n()->t('Days between requery'), DI::config()->get('system', 'poco_requery_days'), DI::l10n()->t('Number of days after which a server is requeried for their contacts and servers it knows of. This is only used when the discovery is activated.')],
'$poco_local_search' => ['poco_local_search', DI::l10n()->t('Search the local directory'), DI::config()->get('system', 'poco_local_search'), DI::l10n()->t('Search the local directory instead of the global directory. When searching locally, every search will be executed on the global directory in the background. This improves the search results when the search is repeated.')],
'$nodeinfo' => ['nodeinfo', DI::l10n()->t('Publish server information'), DI::config()->get('system', 'nodeinfo'), DI::l10n()->t('If enabled, general server and usage data will be published. The data contains the name and version of the server, number of users with public profiles, number of posts and the activated protocols and connectors. See <a href="http://the-federation.info/">the-federation.info</a> for details.')],

View File

@ -76,7 +76,9 @@ class Cron
Worker::add(Worker::PRIORITY_LOW, 'UpdateGServers');
// run the process to update server directories in the background
Worker::add(Worker::PRIORITY_LOW, 'UpdateServerDirectories');
if (DI::config()->get('system', 'poco_discovery')) {
Worker::add(Worker::PRIORITY_LOW, 'UpdateServerDirectories');
}
// Expire and remove user entries
Worker::add(Worker::PRIORITY_MEDIUM, 'ExpireAndRemoveUsers');

View File

@ -25,9 +25,10 @@ use Friendica\Core\Logger;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\GServer;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Strings;
use GuzzleHttp\Psr7\Uri;
class UpdateGServers
{
@ -53,13 +54,20 @@ class UpdateGServers
$outdated = DBA::count('gserver', $condition);
Logger::info('Server status', ['total' => $total, 'outdated' => $outdated, 'updating' => $limit]);
$gservers = DBA::select('gserver', ['url', 'nurl'], $condition, ['limit' => $limit]);
$gservers = DBA::select('gserver', ['id', 'url', 'nurl', 'failed', 'created', 'last_contact'], $condition, ['limit' => $limit]);
if (!DBA::isResult($gservers)) {
return;
}
$count = 0;
while ($gserver = DBA::fetch($gservers)) {
if (DI::config()->get('system', 'update_active_contacts') && !Contact::exists(['gsid' => $gserver['id'], 'local-data' => true])) {
$next_update = GServer::getNextUpdateDate(!$gserver['failed'], $gserver['created'], $gserver['last_contact']);
Logger::debug('Skip server without contacts with local data', ['url' => $gserver['url'], 'failed' => $gserver['failed'], 'next_update' => $next_update]);
GServer::update(['next_contact' => $next_update], ['nurl' => $gserver['nurl']]);
continue;
}
// Sometimes the "nurl" and "url" doesn't seem to fit, see https://forum.friendi.ca/display/ec054ce7-155f-c94d-6159-f50372664245
// There are duplicated "url" but not "nurl". So we check both addresses instead of just overwriting them,
// since that would mean loosing data.

View File

@ -36,6 +36,10 @@ class UpdateServerDirectory
*/
public static function execute(array $gserver)
{
if (!DI::config()->get('system', 'poco_discovery')) {
return;
}
if ($gserver['directory-type'] == GServer::DT_MASTODON) {
self::discoverMastodonDirectory($gserver);
} elseif (!empty($gserver['poco'])) {

View File

@ -40,6 +40,10 @@ class UpdateServerPeers
*/
public static function execute(string $url)
{
if (!DI::config()->get('system', 'poco_discovery')) {
return;
}
$ret = DI::httpClient()->get($url . '/api/v1/instance/peers', HttpClientAccept::JSON);
if (!$ret->isSuccess() || empty($ret->getBody())) {
Logger::info('Server is not reachable or does not offer the "peers" endpoint', ['url' => $url]);

View File

@ -212,6 +212,14 @@ return [
// The fully-qualified URL of this Friendica node.
// Used by the worker in a non-HTTP execution environment.
'url' => '',
// poco_discovery (Boolean)
// If enabled, the system will check for the existance of other contacts and servers
'poco_discovery' => false,
// poco_requery_days (Integer)
// Number of days after which a server is requeried for their contacts and servers it knows of.
'poco_requery_days' => 30,
],
// Used in the admin settings to lock certain features

File diff suppressed because it is too large Load Diff

View File

@ -101,9 +101,10 @@
<h2>{{$portable_contacts}}</h2>
{{include file="field_select.tpl" field=$contact_discovery}}
{{include file="field_checkbox.tpl" field=$update_active_contacts}}
{{include file="field_checkbox.tpl" field=$synchronize_directory}}
{{include file="field_input.tpl" field=$poco_requery_days}}
{{include file="field_checkbox.tpl" field=$poco_discovery}}
{{include file="field_input.tpl" field=$poco_requery_days}}
{{include file="field_checkbox.tpl" field=$poco_local_search}}
<div class="submit"><input type="submit" name="page_site" value="{{$submit}}"/></div>

View File

@ -217,6 +217,7 @@
<div id="admin-settings-contacts-collapse" class="panel-collapse collapse" role="tabpanel" aria-labelledby="admin-settings-cocontactsrporate">
<div class="panel-body">
{{include file="field_select.tpl" field=$contact_discovery}}
{{include file="field_checkbox.tpl" field=$update_active_contacts}}
{{include file="field_checkbox.tpl" field=$synchronize_directory}}
{{include file="field_checkbox.tpl" field=$poco_discovery}}
{{include file="field_input.tpl" field=$poco_requery_days}}