]> git.mxchange.org Git - friendica.git/commitdiff
Improved control about the contact/server updates
authorMichael <heluecht@pirati.ca>
Mon, 27 Nov 2023 19:00:12 +0000 (19:00 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 27 Nov 2023 19:00:12 +0000 (19:00 +0000)
src/Model/GServer.php
src/Module/Admin/Site.php
src/Worker/Cron.php
src/Worker/UpdateGServers.php
src/Worker/UpdateServerDirectory.php
src/Worker/UpdateServerPeers.php
static/settings.config.php
view/templates/admin/site.tpl
view/theme/frio/templates/admin/site.tpl

index aac3ccd9a44e13edb49835d2bc62705dce3bb2e2..432914e178dee2940445665735e916684de97969 100644 (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'],
index 941caa06823af6369de21d21514eca3f7ff78f7d..55f9b8d5c54d72944b56d60e7bbf9f60576ea23c 100644 (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.')],
index accf76d56e1dd6fd7180f45412da3a8983b6cb18..66244af893c840d86ce3bf104e09094fc1c8b25f 100644 (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');
index 0e328578c4b66f52cbb9d8cdf3a4fc865e3a9784..5b1debaeafc22e2119ee294c68b69077ac1fe3f0 100644 (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.
index c7a3b8b2b3ad37ff67b84b3b7fdba75d9515376f..aacf4b8dc4bd727e5fa0c64c96b445031a0d08cf 100644 (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'])) {
index 4829b538cf18fcbb11fa477d08143e2cc8086705..aa5f35c0fc612df5a1a3ecbd4067e2cfd94c3623 100644 (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]);
index 40e479938059ddd1db1c46aff85d845e64c55635..1ff4d5077b3b2d9e5269895423b40f82ed802408 100644 (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
index 17c318907061a4530acfffecd4b6c8c908415146..0440343ba229ddfa49f41230d5ae11760d82e292 100644 (file)
 
                <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>
 
index e440451a6f2bf3bcebcbaa7a5cfefcc851769f39..002d65a1fdda12553266e2bdd180ad4f90acbfac 100644 (file)
                                <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}}