mirror of
https://github.com/friendica/friendica
synced 2025-01-24 09:39:46 +00:00
New option to only update contacts with local relations
This commit is contained in:
parent
bb252e326f
commit
c6a9e7aa4c
8 changed files with 416 additions and 360 deletions
|
@ -362,10 +362,8 @@ class Contact
|
|||
return [];
|
||||
}
|
||||
|
||||
$background_update = DI::config()->get('system', 'update_active_contacts') ? $contact['local-data'] : true;
|
||||
|
||||
// Update the contact in the background if needed
|
||||
if ($background_update && !self::isLocal($url) && Protocol::supportsProbe($contact['network']) && ($contact['next-update'] < DateTimeFormat::utcNow())) {
|
||||
if (UpdateContact::isUpdatable($contact['id'])) {
|
||||
try {
|
||||
UpdateContact::add(['priority' => Worker::PRIORITY_LOW, 'dont_fork' => true], $contact['id']);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
|
@ -537,6 +535,17 @@ class Contact
|
|||
return DBA::exists('account-user-view', ["`pid` = ? AND `uid` != ? AND `rel` IN (?, ?)", $cid, 0, self::SHARING, self::FRIEND]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the provided public contact id has got relations with someone on this system
|
||||
*
|
||||
* @param integer $cid Public Contact Id
|
||||
* @return boolean Contact has followers or sharers on this system
|
||||
*/
|
||||
public static function hasRelations(int $cid): bool
|
||||
{
|
||||
return DBA::exists('account-user-view', ["`pid` = ? AND `uid` != ? AND `rel` IN (?, ?, ?)", $cid, 0, self::FOLLOWER, self::SHARING, self::FRIEND]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the basepath for a given contact link
|
||||
*
|
||||
|
@ -1318,9 +1327,7 @@ class Contact
|
|||
if (!empty($contact)) {
|
||||
$contact_id = $contact['id'];
|
||||
|
||||
$background_update = DI::config()->get('system', 'update_active_contacts') ? $contact['local-data'] : true;
|
||||
|
||||
if ($background_update && !self::isLocal($url) && Protocol::supportsProbe($contact['network']) && ($contact['next-update'] < DateTimeFormat::utcNow())) {
|
||||
if (UpdateContact::isUpdatable($contact['id'])) {
|
||||
try {
|
||||
UpdateContact::add(['priority' => Worker::PRIORITY_LOW, 'dont_fork' => true], $contact['id']);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
|
|
|
@ -2488,10 +2488,6 @@ class GServer
|
|||
*/
|
||||
public static function discover()
|
||||
{
|
||||
if (!DI::config()->get('system', 'discover_servers')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Update the server list
|
||||
self::discoverFederation();
|
||||
|
||||
|
|
|
@ -105,6 +105,7 @@ class Site extends BaseAdmin
|
|||
$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);
|
||||
$update_known_contacts = (!empty($_POST['update_known_contacts']) ? intval(trim($_POST['update_known_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);
|
||||
|
@ -178,6 +179,7 @@ class Site extends BaseAdmin
|
|||
$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', 'update_known_contacts' , $update_known_contacts);
|
||||
$transactionConfig->set('system', 'synchronize_directory' , $synchronize_directory);
|
||||
$transactionConfig->set('system', 'poco_requery_days' , $poco_requery_days);
|
||||
$transactionConfig->set('system', 'poco_discovery' , $poco_discovery);
|
||||
|
@ -546,6 +548,7 @@ class Site extends BaseAdmin
|
|||
'<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.')],
|
||||
'$update_known_contacts' => ['update_known_contacts', DI::l10n()->t('Only update contacts with relations'), DI::config()->get('system', 'update_known_contacts'), DI::l10n()->t('If enabled, the system will only look for changes in contacts that are in a contact list of a user 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_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.')],
|
||||
|
|
|
@ -7,10 +7,12 @@
|
|||
|
||||
namespace Friendica\Worker;
|
||||
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
|
||||
class UpdateContact
|
||||
{
|
||||
|
@ -54,4 +56,38 @@ class UpdateContact
|
|||
DI::logger()->debug('Update contact', ['id' => $contact_id]);
|
||||
return Worker::add($run_parameters, 'UpdateContact', $contact_id);
|
||||
}
|
||||
|
||||
public static function isUpdatable(int $contact_id): bool
|
||||
{
|
||||
$contact = Contact::selectFirst(['next-update', 'local-data', 'url', 'network', 'uid'], ['id' => $contact_id]);
|
||||
if (empty($contact)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($contact['next-update'] > DateTimeFormat::utcNow()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (DI::config()->get('system', 'update_known_contacts') && ($contact['uid'] == 0) && !Contact::hasRelations($contact_id)) {
|
||||
Logger::debug('No local relations, contact will not be updated', ['id' => $contact_id, 'url' => $contact['url'], 'network' => $contact['network']]);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (DI::config()->get('system', 'update_active_contacts') && $contact['local-data']) {
|
||||
Logger::debug('No local data, contact will not be updated', ['id' => $contact_id, 'url' => $contact['url'], 'network' => $contact['network']]);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Contact::isLocal($contact['url'])) {
|
||||
Logger::debug('Local contact will not be updated', ['id' => $contact_id, 'url' => $contact['url'], 'network' => $contact['network']]);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Protocol::supportsProbe($contact['network'])) {
|
||||
Logger::debug('Contact does not support probe, it will not be updated', ['id' => $contact_id, 'url' => $contact['url'], 'network' => $contact['network']]);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -257,6 +257,10 @@ return [
|
|||
// When activated, only public contacts will be activated regularly that are used for example in items or tags.
|
||||
'update_active_contacts' => false,
|
||||
|
||||
// update_known_contacts (Boolean)
|
||||
// When activated, only public contacts will be activated regularly that are in a contact list of a local user.
|
||||
'update_known_contacts' => false,
|
||||
|
||||
// url (String)
|
||||
// The fully-qualified URL of this Friendica node.
|
||||
// Used by the worker in a non-HTTP execution environment.
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -112,6 +112,7 @@
|
|||
<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=$update_known_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}}
|
||||
|
|
|
@ -228,6 +228,7 @@
|
|||
<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=$update_known_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}}
|
||||
|
|
Loading…
Add table
Reference in a new issue