Merge pull request #13674 from annando/server-discovery
Improved control about the contact/server updates
This commit is contained in:
commit
de807e6378
|
@ -2373,6 +2373,10 @@ class GServer
|
||||||
*/
|
*/
|
||||||
public static function discover()
|
public static function discover()
|
||||||
{
|
{
|
||||||
|
if (!DI::config('system', 'discover_servers')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Update the server list
|
// Update the server list
|
||||||
self::discoverFederation();
|
self::discoverFederation();
|
||||||
|
|
||||||
|
@ -2380,10 +2384,6 @@ class GServer
|
||||||
|
|
||||||
$requery_days = intval(DI::config()->get('system', 'poco_requery_days'));
|
$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));
|
$last_update = date('c', time() - (60 * 60 * 24 * $requery_days));
|
||||||
|
|
||||||
$gservers = DBA::select('gserver', ['id', 'url', 'nurl', 'network', 'poco', 'directory-type'],
|
$gservers = DBA::select('gserver', ['id', 'url', 'nurl', 'network', 'poco', 'directory-type'],
|
||||||
|
|
|
@ -111,6 +111,7 @@ class Site extends BaseAdmin
|
||||||
$min_memory = (!empty($_POST['min_memory']) ? intval(trim($_POST['min_memory'])) : 0);
|
$min_memory = (!empty($_POST['min_memory']) ? intval(trim($_POST['min_memory'])) : 0);
|
||||||
$optimize_tables = (!empty($_POST['optimize_tables']) ? intval(trim($_POST['optimize_tables'])) : false);
|
$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);
|
$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);
|
$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_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);
|
$poco_discovery = (!empty($_POST['poco_discovery']) ? intval(trim($_POST['poco_discovery'])) : false);
|
||||||
|
@ -160,6 +161,7 @@ class Site extends BaseAdmin
|
||||||
$transactionConfig->set('system', 'min_memory' , $min_memory);
|
$transactionConfig->set('system', 'min_memory' , $min_memory);
|
||||||
$transactionConfig->set('system', 'optimize_tables' , $optimize_tables);
|
$transactionConfig->set('system', 'optimize_tables' , $optimize_tables);
|
||||||
$transactionConfig->set('system', 'contact_discovery' , $contact_discovery);
|
$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', 'synchronize_directory' , $synchronize_directory);
|
||||||
$transactionConfig->set('system', 'poco_requery_days' , $poco_requery_days);
|
$transactionConfig->set('system', 'poco_requery_days' , $poco_requery_days);
|
||||||
$transactionConfig->set('system', 'poco_discovery' , $poco_discovery);
|
$transactionConfig->set('system', 'poco_discovery' , $poco_discovery);
|
||||||
|
@ -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('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>',
|
'<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],
|
$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.')],
|
'$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 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_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_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.')],
|
'$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.')],
|
'$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.')],
|
||||||
|
|
|
@ -76,7 +76,9 @@ class Cron
|
||||||
Worker::add(Worker::PRIORITY_LOW, 'UpdateGServers');
|
Worker::add(Worker::PRIORITY_LOW, 'UpdateGServers');
|
||||||
|
|
||||||
// run the process to update server directories in the background
|
// run the process to update server directories in the background
|
||||||
|
if (DI::config()->get('system', 'poco_discovery')) {
|
||||||
Worker::add(Worker::PRIORITY_LOW, 'UpdateServerDirectories');
|
Worker::add(Worker::PRIORITY_LOW, 'UpdateServerDirectories');
|
||||||
|
}
|
||||||
|
|
||||||
// Expire and remove user entries
|
// Expire and remove user entries
|
||||||
Worker::add(Worker::PRIORITY_MEDIUM, 'ExpireAndRemoveUsers');
|
Worker::add(Worker::PRIORITY_MEDIUM, 'ExpireAndRemoveUsers');
|
||||||
|
|
|
@ -25,9 +25,10 @@ use Friendica\Core\Logger;
|
||||||
use Friendica\Core\Worker;
|
use Friendica\Core\Worker;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
|
use Friendica\Model\Contact;
|
||||||
|
use Friendica\Model\GServer;
|
||||||
use Friendica\Util\DateTimeFormat;
|
use Friendica\Util\DateTimeFormat;
|
||||||
use Friendica\Util\Strings;
|
use Friendica\Util\Strings;
|
||||||
use GuzzleHttp\Psr7\Uri;
|
|
||||||
|
|
||||||
class UpdateGServers
|
class UpdateGServers
|
||||||
{
|
{
|
||||||
|
@ -53,13 +54,20 @@ class UpdateGServers
|
||||||
$outdated = DBA::count('gserver', $condition);
|
$outdated = DBA::count('gserver', $condition);
|
||||||
Logger::info('Server status', ['total' => $total, 'outdated' => $outdated, 'updating' => $limit]);
|
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)) {
|
if (!DBA::isResult($gservers)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$count = 0;
|
$count = 0;
|
||||||
while ($gserver = DBA::fetch($gservers)) {
|
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
|
// 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,
|
// There are duplicated "url" but not "nurl". So we check both addresses instead of just overwriting them,
|
||||||
// since that would mean loosing data.
|
// since that would mean loosing data.
|
||||||
|
|
|
@ -36,6 +36,10 @@ class UpdateServerDirectory
|
||||||
*/
|
*/
|
||||||
public static function execute(array $gserver)
|
public static function execute(array $gserver)
|
||||||
{
|
{
|
||||||
|
if (!DI::config()->get('system', 'poco_discovery')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ($gserver['directory-type'] == GServer::DT_MASTODON) {
|
if ($gserver['directory-type'] == GServer::DT_MASTODON) {
|
||||||
self::discoverMastodonDirectory($gserver);
|
self::discoverMastodonDirectory($gserver);
|
||||||
} elseif (!empty($gserver['poco'])) {
|
} elseif (!empty($gserver['poco'])) {
|
||||||
|
|
|
@ -40,6 +40,10 @@ class UpdateServerPeers
|
||||||
*/
|
*/
|
||||||
public static function execute(string $url)
|
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);
|
$ret = DI::httpClient()->get($url . '/api/v1/instance/peers', HttpClientAccept::JSON);
|
||||||
if (!$ret->isSuccess() || empty($ret->getBody())) {
|
if (!$ret->isSuccess() || empty($ret->getBody())) {
|
||||||
Logger::info('Server is not reachable or does not offer the "peers" endpoint', ['url' => $url]);
|
Logger::info('Server is not reachable or does not offer the "peers" endpoint', ['url' => $url]);
|
||||||
|
|
|
@ -212,6 +212,14 @@ return [
|
||||||
// The fully-qualified URL of this Friendica node.
|
// The fully-qualified URL of this Friendica node.
|
||||||
// Used by the worker in a non-HTTP execution environment.
|
// Used by the worker in a non-HTTP execution environment.
|
||||||
'url' => '',
|
'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
|
// Used in the admin settings to lock certain features
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -101,9 +101,10 @@
|
||||||
|
|
||||||
<h2>{{$portable_contacts}}</h2>
|
<h2>{{$portable_contacts}}</h2>
|
||||||
{{include file="field_select.tpl" field=$contact_discovery}}
|
{{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=$synchronize_directory}}
|
||||||
{{include file="field_input.tpl" field=$poco_requery_days}}
|
|
||||||
{{include file="field_checkbox.tpl" field=$poco_discovery}}
|
{{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}}
|
{{include file="field_checkbox.tpl" field=$poco_local_search}}
|
||||||
<div class="submit"><input type="submit" name="page_site" value="{{$submit}}"/></div>
|
<div class="submit"><input type="submit" name="page_site" value="{{$submit}}"/></div>
|
||||||
|
|
||||||
|
|
|
@ -217,6 +217,7 @@
|
||||||
<div id="admin-settings-contacts-collapse" class="panel-collapse collapse" role="tabpanel" aria-labelledby="admin-settings-cocontactsrporate">
|
<div id="admin-settings-contacts-collapse" class="panel-collapse collapse" role="tabpanel" aria-labelledby="admin-settings-cocontactsrporate">
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
{{include file="field_select.tpl" field=$contact_discovery}}
|
{{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=$synchronize_directory}}
|
||||||
{{include file="field_checkbox.tpl" field=$poco_discovery}}
|
{{include file="field_checkbox.tpl" field=$poco_discovery}}
|
||||||
{{include file="field_input.tpl" field=$poco_requery_days}}
|
{{include file="field_input.tpl" field=$poco_requery_days}}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user