]> git.mxchange.org Git - friendica.git/commitdiff
Reduce the load of "gfollower"
authorMichael <heluecht@pirati.ca>
Tue, 10 Mar 2020 21:10:59 +0000 (21:10 +0000)
committerMichael <heluecht@pirati.ca>
Tue, 10 Mar 2020 21:10:59 +0000 (21:10 +0000)
src/Model/Contact.php
src/Model/GContact.php
src/Model/Item.php
src/Module/Admin/Site.php
src/Worker/UpdateContact.php
src/Worker/UpdateGContact.php
static/dbstructure.config.php
view/templates/admin/site.tpl
view/theme/frio/templates/admin/site.tpl

index f199012f1f6deac692bd7f9ca8e176f5eef4e071..9ae27994c7e33e3f19b899f411a3b11ff831e368 100644 (file)
@@ -1621,6 +1621,9 @@ class Contact
                                // Update the gcontact entry
                                if ($uid == 0) {
                                        GContact::updateFromPublicContactID($contact_id);
+                                       if (($data['network'] == Protocol::ACTIVITYPUB) && in_array(DI::config()->get('system', 'gcontact_discovery'), [GContact::DISCOVERY_DIRECT, GContact::DISCOVERY_RECURSIVE])) {
+                                               GContact::discoverFollowers($data['url']);
+                                       }
                                }
                        }
                } else {
index 19ab87ca45f09ca6f4486e0ca4f48fecc94e3d68..59c84bc4907b62a0950d22cf4b353441eb5c5062 100644 (file)
@@ -43,6 +43,19 @@ use Friendica\Util\Strings;
  */
 class GContact
 {
+       /**
+        * No discovery of followers/followings
+        */
+       const DISCOVERY_NONE = 0;
+       /**
+        * Only discover followers/followings from direct contacts
+        */
+       const DISCOVERY_DIRECT = 1;
+       /**
+        * Recursive discovery of followers/followings
+        */
+       const DISCOVERY_RECURSIVE = 2;
+
        /**
         * Search global contact table by nick or name
         *
index fe62e888d0d3d03fa2616655c7ab9ab2ef5e1d5c..3acf9598802b80acc5c7fc425002d05bd42dfa52 100644 (file)
@@ -1695,7 +1695,7 @@ class Item
 
                        $fields = ['uri', 'parent-uri', 'id', 'deleted',
                                'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
-                               'wall', 'private', 'forum_mode', 'origin'];
+                               'wall', 'private', 'forum_mode', 'origin', 'author-id'];
                        $condition = ['uri' => $item['parent-uri'], 'uid' => $item['uid']];
                        $params = ['order' => ['id' => false]];
                        $parent = self::selectFirst($fields, $condition, $params);
@@ -1750,7 +1750,15 @@ class Item
                                        DBA::update('thread', ['mention' => true], ['iid' => $parent_id]);
                                        Logger::log('tagged thread ' . $parent_id . ' as mention for user ' . $item['uid'], Logger::DEBUG);
                                }
-                       } else {
+
+                               // Update the contact relations
+                               if ($item['author-id'] != $parent['author-id']) {
+                                       $fields = ['cid' => $parent['author-id'], 'relation-cid' => $item['author-id']];
+                                       if (!DBA::exists('contact-relation', $fields)) {
+                                               DBA::insert('contact-relation', $fields, true);
+                                       }
+                               }
+               } else {
                                /*
                                 * Allow one to see reply tweets from status.net even when
                                 * we don't have or can't see the original post.
index 846280c4f12915ca6e457d01dfd7846df7da75d1..00ca203472c314a17e2f1b66dd4f5b2d019f4889 100644 (file)
@@ -28,6 +28,7 @@ use Friendica\Core\Theme;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
 use Friendica\DI;
+use Friendica\Model\GContact;
 use Friendica\Module\BaseAdmin;
 use Friendica\Module\Register;
 use Friendica\Protocol\PortableContact;
@@ -178,7 +179,7 @@ class Site extends BaseAdmin
                $optimize_max_tablesize = (!empty($_POST['optimize_max_tablesize']) ? intval(trim($_POST['optimize_max_tablesize'])) : 100);
                $optimize_fragmentation = (!empty($_POST['optimize_fragmentation']) ? intval(trim($_POST['optimize_fragmentation'])) : 30);
                $poco_completion        = (!empty($_POST['poco_completion'])        ? intval(trim($_POST['poco_completion']))        : false);
-               $gcontact_discovery     = (!empty($_POST['gcontact_discovery'])     ? intval(trim($_POST['gcontact_discovery']))     : false);
+               $gcontact_discovery     = (!empty($_POST['gcontact_discovery'])     ? intval(trim($_POST['gcontact_discovery']))     : 0);
                $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']))         : PortableContact::DISABLED);
                $poco_discovery_since   = (!empty($_POST['poco_discovery_since'])   ? intval(trim($_POST['poco_discovery_since']))   : 30);
@@ -549,6 +550,12 @@ class Site extends BaseAdmin
                        'develop' => DI::l10n()->t('check the development version')
                ];
 
+               $discovery_choices = [
+                       GContact::DISCOVERY_NONE => DI::l10n()->t('none'),
+                       GContact::DISCOVERY_DIRECT => DI::l10n()->t('Direct contacts'),
+                       GContact::DISCOVERY_RECURSIVE => DI::l10n()->t('Contacts of contacts')
+               ];
+
                $diaspora_able = (DI::baseUrl()->getUrlPath() == '');
 
                $optimize_max_tablesize = DI::config()->get('system', 'optimize_max_tablesize', -1);
@@ -671,7 +678,7 @@ class Site extends BaseAdmin
                        '$optimize_fragmentation' => ['optimize_fragmentation', DI::l10n()->t('Minimum level of fragmentation'), DI::config()->get('system', 'optimize_fragmentation', 30), DI::l10n()->t('Minimum fragmenation level to start the automatic optimization - default value is 30%.')],
 
                        '$poco_completion'        => ['poco_completion', DI::l10n()->t('Periodical check of global contacts'), DI::config()->get('system', 'poco_completion'), DI::l10n()->t('If enabled, the global contacts are checked periodically for missing or outdated data and the vitality of the contacts and servers.')],
-                       '$gcontact_discovery'     => ['gcontact_discovery', DI::l10n()->t('Discover followers/followings from global contacts'), DI::config()->get('system', 'gcontact_discovery'), DI::l10n()->t('If enabled, the global contacts are checked for new contacts among their followers and following contacts. This option will create huge masses of jobs, so it should only be activated on powerful machines.')],
+                       '$gcontact_discovery'     => ['gcontact_discovery', DI::l10n()->t('Discover followers/followings from global contacts'), (string)intval(DI::config()->get('system', 'gcontact_discovery')), DI::l10n()->t('If enabled, the global contacts are checked for new contacts among their followers and following contacts. This option will create huge masses of jobs, so it should only be activated on powerful machines.'), $discovery_choices],
                        '$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'), (string)intval(DI::config()->get('system', 'poco_discovery')), DI::l10n()->t('Periodically query other servers for contacts. You can choose between "Users": the users on the remote system, "Global Contacts": active contacts that are known on the system. The fallback is meant for Redmatrix servers and older friendica servers, where global contacts weren\'t available. The fallback increases the server load, so the recommended setting is "Users, Global Contacts".'), $poco_discovery_choices],
                        '$poco_discovery_since'   => ['poco_discovery_since', DI::l10n()->t('Timeframe for fetching global contacts'), (string)intval(DI::config()->get('system', 'poco_discovery_since')), DI::l10n()->t('When the discovery is activated, this value defines the timeframe for the activity of the global contacts that are fetched from other servers.'), $poco_discovery_since_choices],
index 342e99550de2085477da8056283679edc189fb2f..67bc45ef982d229798a70bc572b57bfba33863c9 100644 (file)
@@ -23,8 +23,6 @@ namespace Friendica\Worker;
 
 use Friendica\Core\Logger;
 use Friendica\Model\Contact;
-use Friendica\Util\DateTimeFormat;
-use Friendica\Database\DBA;
 
 class UpdateContact
 {
index b88e0899e9a38cb6449bd76c54c5317ff0ac672c..e06356ad46b7bdbfd7918a6fc5ac6706f4b38c30 100644 (file)
@@ -40,7 +40,7 @@ class UpdateGContact
 
                Logger::info('Updated from probe', ['url' => $url, 'force' => $force, 'success' => $success]);
 
-               if ($success && DI::config()->get('system', 'gcontact_discovery')) {
+               if ($success && (DI::config()->get('system', 'gcontact_discovery') == GContact::DISCOVERY_RECURSIVE)) {
                        GContact::discoverFollowers($url);
                }
        }
index cfbee73fbdee91b1284682a4dd5ab10865fad919..94a6e6ec28027fe94305c035e8b9cf9256d4ea89 100755 (executable)
@@ -51,7 +51,7 @@
 use Friendica\Database\DBA;
 
 if (!defined('DB_UPDATE_VERSION')) {
-       define('DB_UPDATE_VERSION', 1337);
+       define('DB_UPDATE_VERSION', 1338);
 }
 
 return [
@@ -317,6 +317,17 @@ return [
                        "issued-id" => ["issued-id(64)"],
                ]
        ],
+       "contact-relation" => [
+               "comment" => "Contact relations",
+               "fields" => [
+                       "cid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "contact the related contact had interacted with"],
+                       "relation-cid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "related contact who had interacted with the contact"],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["cid", "relation-cid"],
+                       "relation-cid" => ["relation-cid"],
+               ]
+       ],
        "conv" => [
                "comment" => "private messages",
                "fields" => [
index 9e601b078c42855fc4c159b1435d201494071d2d..b6d0c5930da71066c0437c30cc191f16568a255a 100644 (file)
@@ -98,7 +98,7 @@
 
        <h3>{{$portable_contacts}}</h3>
        {{include file="field_checkbox.tpl" field=$poco_completion}}
-       {{include file="field_checkbox.tpl" field=$gcontact_discovery}}
+       {{include file="field_select.tpl" field=$gcontact_discovery}}
        {{include file="field_input.tpl" field=$poco_requery_days}}
        {{include file="field_select.tpl" field=$poco_discovery}}
        {{include file="field_select.tpl" field=$poco_discovery_since}}
index e4b05d453db14a99421b0758cd7de81a2cb376e0..902b8a00026cb3fef6cf1ca3d984308a1bffc2d1 100644 (file)
                                <div id="admin-settings-contacts-collapse" class="panel-collapse collapse" role="tabpanel" aria-labelledby="admin-settings-cocontactsrporate">
 
                                        {{include file="field_checkbox.tpl" field=$poco_completion}}
-                                       {{include file="field_checkbox.tpl" field=$gcontact_discovery}}
+                                       {{include file="field_select.tpl" field=$gcontact_discovery}}
                                        {{include file="field_input.tpl" field=$poco_requery_days}}
                                        {{include file="field_select.tpl" field=$poco_discovery}}
                                        {{include file="field_select.tpl" field=$poco_discovery_since}}