From: Michael Date: Mon, 27 Nov 2023 19:00:12 +0000 (+0000) Subject: Improved control about the contact/server updates X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=077c9ff0c998f3a1da3381acceaabff3453739af;p=friendica.git Improved control about the contact/server updates --- diff --git a/src/Model/GServer.php b/src/Model/GServer.php index aac3ccd9a4..432914e178 100644 --- a/src/Model/GServer.php +++ b/src/Model/GServer.php @@ -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'], diff --git a/src/Module/Admin/Site.php b/src/Module/Admin/Site.php index 941caa0682..55f9b8d5c5 100644 --- a/src/Module/Admin/Site.php +++ b/src/Module/Admin/Site.php @@ -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 '
  • ' . DI::l10n()->t('Local contacts - contacts of our local contacts are discovered for their followers/followings.') . '
  • ' . '
  • ' . DI::l10n()->t('Interactors - contacts of our local contacts and contacts who interacted on locally visible postings are discovered for their followers/followings.') . '
  • ', $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 the-federation.info for details.')], diff --git a/src/Worker/Cron.php b/src/Worker/Cron.php index accf76d56e..66244af893 100644 --- a/src/Worker/Cron.php +++ b/src/Worker/Cron.php @@ -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'); diff --git a/src/Worker/UpdateGServers.php b/src/Worker/UpdateGServers.php index 0e328578c4..5b1debaeaf 100644 --- a/src/Worker/UpdateGServers.php +++ b/src/Worker/UpdateGServers.php @@ -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. diff --git a/src/Worker/UpdateServerDirectory.php b/src/Worker/UpdateServerDirectory.php index c7a3b8b2b3..aacf4b8dc4 100644 --- a/src/Worker/UpdateServerDirectory.php +++ b/src/Worker/UpdateServerDirectory.php @@ -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'])) { diff --git a/src/Worker/UpdateServerPeers.php b/src/Worker/UpdateServerPeers.php index 4829b538cf..aa5f35c0fc 100644 --- a/src/Worker/UpdateServerPeers.php +++ b/src/Worker/UpdateServerPeers.php @@ -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]); diff --git a/static/settings.config.php b/static/settings.config.php index 40e4799380..1ff4d5077b 100644 --- a/static/settings.config.php +++ b/static/settings.config.php @@ -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 diff --git a/view/templates/admin/site.tpl b/view/templates/admin/site.tpl index 17c3189070..0440343ba2 100644 --- a/view/templates/admin/site.tpl +++ b/view/templates/admin/site.tpl @@ -101,9 +101,10 @@

    {{$portable_contacts}}

    {{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}}
    diff --git a/view/theme/frio/templates/admin/site.tpl b/view/theme/frio/templates/admin/site.tpl index e440451a6f..002d65a1fd 100644 --- a/view/theme/frio/templates/admin/site.tpl +++ b/view/theme/frio/templates/admin/site.tpl @@ -217,6 +217,7 @@
    {{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}}