]> git.mxchange.org Git - friendica.git/commitdiff
New table for relations between global contacts - will replace glink in the future
authorMichael <heluecht@pirati.ca>
Fri, 6 Mar 2020 08:08:49 +0000 (08:08 +0000)
committerMichael <heluecht@pirati.ca>
Fri, 6 Mar 2020 08:08:49 +0000 (08:08 +0000)
database.sql
src/Model/GContact.php
static/dbstructure.config.php

index 3cb87fc90ae88e0a7a4cd38e8fea87b87920165b..a5e94f3f542280714feefacf35c5a52e6730ae8d 100644 (file)
@@ -1,6 +1,6 @@
 -- ------------------------------------------
 -- Friendica 2020.03-dev (Dalmatian Bellflower)
--- DB_UPDATE_VERSION 1335
+-- DB_UPDATE_VERSION 1336
 -- ------------------------------------------
 
 
@@ -419,6 +419,16 @@ CREATE TABLE IF NOT EXISTS `gcontact` (
         INDEX `updated` (`updated`)
 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='global contacts';
 
+--
+-- TABLE gfollower
+--
+CREATE TABLE IF NOT EXISTS `gfollower` (
+       `gcid` int unsigned NOT NULL DEFAULT 0 COMMENT 'global contact',
+       `follower-gcid` int unsigned NOT NULL DEFAULT 0 COMMENT 'global contact of the follower',
+        PRIMARY KEY(`gcid`,`follower-gcid`),
+        INDEX `follower-gcid` (`follower-gcid`)
+) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Followers of global contacts';
+
 --
 -- TABLE glink
 --
index 6f41fd732575f009b2b8b88937c39799ca1d425a..86b6bb94cdc8c91396ccb90bea1eabbd08104d13 100644 (file)
@@ -1299,10 +1299,25 @@ class GContact
                }
 
                if (!empty($followers) || !empty($followings)) {
+                       $gcontact = DBA::selectFirst('gcontact', ['id'], ['nurl' => Strings::normaliseLink(($url))]);
+                       $gcid = $gcontact['id'];
+                       if (!empty($followers)) {
+                               // Clear the follower list, since it will be recreated in the next step
+                               DBA::delete('gfollower', ['gcid' => $gcid]);
+                       }
+
                        $contacts = array_unique(array_merge($followers, $followings));
                        Logger::info('Discover AP contacts', ['url' => $url, 'contacts' => count($contacts)]);
                        foreach ($contacts as $contact) {
-                               if (DBA::exists('gcontact', ['nurl' => Strings::normaliseLink(($contact))])) {
+                               $gcontact = DBA::selectFirst('gcontact', ['id'], ['nurl' => Strings::normaliseLink(($contact))]);
+                               if (DBA::isResult($gcontact)) {
+                                       if (in_array($contact, $followers)) {
+                                               $fields = ['gcid' => $gcid, 'follower-gcid' => $gcontact['id']];
+                                       } elseif (in_array($contact, $followings)) {
+                                               $fields = ['gcid' => $gcontact['id'], 'follower-gcid' => $gcid];
+                                       }
+                                       Logger::info('Set relation between contacts', $fields);
+                                       DBA::update('gfollower', $fields, $fields, true);
                                        continue;
                                }
                                Logger::info('Discover new AP contact', ['url' => $contact]);
index 0c0b289414ec0d73e2481cc97e2807cd792efc84..11695b59243ca3598abfddc5a46aba66b78ecf35 100755 (executable)
@@ -51,7 +51,7 @@
 use Friendica\Database\DBA;
 
 if (!defined('DB_UPDATE_VERSION')) {
-       define('DB_UPDATE_VERSION', 1335);
+       define('DB_UPDATE_VERSION', 1336);
 }
 
 return [
@@ -490,6 +490,17 @@ return [
                        "updated" => ["updated"],
                ]
        ],
+       "gfollower" => [
+               "comment" => "Followers of global contacts",
+               "fields" => [
+                       "gcid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "primary" => "1", "relation" => ["gcontact" => "id"], "comment" => "global contact"],
+                       "follower-gcid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "primary" => "1", "relation" => ["gcontact" => "id"], "comment" => "global contact of the follower"],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["gcid", "follower-gcid"],
+                       "follower-gcid" => ["follower-gcid"],
+               ]
+       ],
        "glink" => [
                "comment" => "'friends of friends' linkages derived from poco",
                "fields" => [