]> git.mxchange.org Git - friendica.git/commitdiff
Changes after review
authorMichael <heluecht@pirati.ca>
Sat, 31 Dec 2022 16:20:18 +0000 (16:20 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 31 Dec 2022 16:20:18 +0000 (16:20 +0000)
database.sql
doc/database/db_delivery-queue.md
src/Core/Worker.php
src/Core/Worker/Cron.php
src/Model/GServer.php
src/Worker/BulkDelivery.php
src/Worker/Notifier.php
src/Worker/UpdateGServer.php
static/dbstructure.config.php

index 02481bc007f177f1371a9c63a2999aa528bafb0c..2d5a1dbaa0b50babe166da48543fab138d927b3f 100644 (file)
@@ -583,11 +583,11 @@ CREATE TABLE IF NOT EXISTS `delayed-post` (
 -- TABLE delivery-queue
 --
 CREATE TABLE IF NOT EXISTS `delivery-queue` (
-       `gsid` int unsigned NOT NULL COMMENT 'Global Server ID',
-       `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
+       `gsid` int unsigned NOT NULL COMMENT 'Target server',
+       `uri-id` int unsigned NOT NULL COMMENT 'Delivered post',
        `created` datetime COMMENT '',
        `command` varbinary(32) COMMENT '',
-       `cid` int unsigned COMMENT 'contact_id (ID of the contact in contact table)',
+       `cid` int unsigned COMMENT 'Target contact',
        `uid` mediumint unsigned COMMENT 'Delivering user',
        `failed` tinyint DEFAULT 0 COMMENT 'Number of times the delivery has failed',
         PRIMARY KEY(`uri-id`,`gsid`),
index a46f7ac3a5c43305e099fc93bdd27cb5e37363a9..46623a54e0f12b5b542718a52278d969a4afe87a 100644 (file)
@@ -6,15 +6,15 @@ Delivery data for posts for the batch processing
 Fields
 ------
 
-| Field   | Description                                               | Type               | Null | Key | Default | Extra |
-| ------- | --------------------------------------------------------- | ------------------ | ---- | --- | ------- | ----- |
-| gsid    | Global Server ID                                          | int unsigned       | NO   | PRI | NULL    |       |
-| uri-id  | Id of the item-uri table entry that contains the item uri | int unsigned       | NO   | PRI | NULL    |       |
-| created |                                                           | datetime           | YES  |     | NULL    |       |
-| command |                                                           | varbinary(32)      | YES  |     | NULL    |       |
-| cid     | contact_id (ID of the contact in contact table)           | int unsigned       | YES  |     | NULL    |       |
-| uid     | Delivering user                                           | mediumint unsigned | YES  |     | NULL    |       |
-| failed  | Number of times the delivery has failed                   | tinyint            | YES  |     | 0       |       |
+| Field   | Description                             | Type               | Null | Key | Default | Extra |
+| ------- | --------------------------------------- | ------------------ | ---- | --- | ------- | ----- |
+| gsid    | Target server                           | int unsigned       | NO   | PRI | NULL    |       |
+| uri-id  | Delivered post                          | int unsigned       | NO   | PRI | NULL    |       |
+| created |                                         | datetime           | YES  |     | NULL    |       |
+| command |                                         | varbinary(32)      | YES  |     | NULL    |       |
+| cid     | Target contact                          | int unsigned       | YES  |     | NULL    |       |
+| uid     | Delivering user                         | mediumint unsigned | YES  |     | NULL    |       |
+| failed  | Number of times the delivery has failed | tinyint            | YES  |     | 0       |       |
 
 Indexes
 ------------
index 3c5d38c09f8f7a22508ea0f990ca6d1cdaf49837..92725240ea5f7d47dd3b3c63de91cadf22b54857 100644 (file)
@@ -1264,7 +1264,7 @@ class Worker
 
                $command = array_shift($args);
                $parameters = json_encode($args);
-               $queue = DBA::selectFirst('workerqueue', [], ['command' => $command, 'parameter' => $parameters, 'done' => false]);
+               $queue = DBA::selectFirst('workerqueue', ['id', 'priority'], ['command' => $command, 'parameter' => $parameters, 'done' => false]);
                $added = 0;
 
                if (!is_int($priority) || !in_array($priority, self::PRIORITIES)) {
index 5fdda1396ca6c3a0574ad5a99cfd8418871ad5f9..8e354344b87f8254a784982840dd9fd4843777ee 100644 (file)
@@ -210,7 +210,7 @@ class Cron
                                Delivery::removeFailedQueue($delivery['gsid']);
                        }
 
-                       if (($delivery['failed'] < 3) || GServer::reachableById($delivery['gsid'])) {
+                       if (($delivery['failed'] < 3) || GServer::isReachableById($delivery['gsid'])) {
                                $priority = Worker::PRIORITY_HIGH;
                        } elseif ($delivery['failed'] < 6) {
                                $priority = Worker::PRIORITY_MEDIUM;
index 8adabf847e5cfa2c13e18c8efbec409deb64dcb5..477b1f3232f69a312b7b047aca808768664b02f2 100644 (file)
@@ -170,7 +170,7 @@ class GServer
         * @param integer $gsid
         * @return boolean
         */
-       private static function defunctByArray(array $gserver): bool
+       private static function isDefunct(array $gserver): bool
        {
                return ($gserver['failed'] || in_array($gserver['network'], Protocol::FEDERATED)) &&
                        ($gserver['last_contact'] >= $gserver['created']) &&
@@ -184,7 +184,7 @@ class GServer
         * @param integer $gsid
         * @return boolean
         */
-       public static function defunct(int $gsid): bool
+       public static function isDefunctById(int $gsid): bool
        {
                $gserver = DBA::selectFirst('gserver', ['url', 'next_contact', 'last_contact', 'last_failure', 'created', 'failed', 'network'], ['id' => $gsid]);
                if (empty($gserver)) {
@@ -193,7 +193,7 @@ class GServer
                        if (strtotime($gserver['next_contact']) < time()) {
                                Worker::add(Worker::PRIORITY_LOW, 'UpdateGServer', $gserver['url'], false);
                        }
-                       return self::defunctByArray($gserver);
+                       return self::isDefunct($gserver);
                }
        }
 
@@ -203,7 +203,7 @@ class GServer
         * @param integer $gsid
         * @return boolean
         */
-       public static function reachableById(int $gsid): bool
+       public static function isReachableById(int $gsid): bool
        {
                $gserver = DBA::selectFirst('gserver', ['url', 'next_contact', 'failed', 'network'], ['id' => $gsid]);
                if (empty($gserver)) {
@@ -398,7 +398,7 @@ class GServer
         *
         * @param string $url
         */
-       public static function setFailure(string $url)
+       public static function setFailureByUrl(string $url)
        {
                $gserver = DBA::selectFirst('gserver', [], ['nurl' => Strings::normaliseLink($url)]);
                if (DBA::isResult($gserver)) {
@@ -407,7 +407,7 @@ class GServer
                        'next_contact' => $next_update, 'network' => Protocol::PHANTOM, 'detection-method' => null],
                        ['nurl' => Strings::normaliseLink($url)]);
                        Logger::info('Set failed status for existing server', ['url' => $url]);
-                       if (self::defunctByArray($gserver)) {
+                       if (self::isDefunct($gserver)) {
                                Contact::update(['archive' => true], ['gsid' => $gserver['id']]);
                        }
                        return;
@@ -462,7 +462,7 @@ class GServer
 
                // If the URL missmatches, then we mark the old entry as failure
                if (!Strings::compareLink($url, $original_url)) {
-                       self::setFailure($original_url);
+                       self::setFailureByUrl($original_url);
                        if (!self::getID($url, true)) {
                                self::detect($url, $network, $only_nodeinfo);
                        }
@@ -471,7 +471,7 @@ class GServer
 
                $valid_url = Network::isUrlValid($url);
                if (!$valid_url) {
-                       self::setFailure($url);
+                       self::setFailureByUrl($url);
                        return false;
                } else {
                        $valid_url = rtrim($valid_url, '/');
@@ -483,7 +483,7 @@ class GServer
                        if (((parse_url($url, PHP_URL_HOST) != parse_url($valid_url, PHP_URL_HOST)) && (parse_url($url, PHP_URL_PATH) == parse_url($valid_url, PHP_URL_PATH))) ||
                                (((parse_url($url, PHP_URL_HOST) != parse_url($valid_url, PHP_URL_HOST)) || (parse_url($url, PHP_URL_PATH) != parse_url($valid_url, PHP_URL_PATH))) && empty(parse_url($valid_url, PHP_URL_PATH)))) {
                                Logger::debug('Found redirect. Mark old entry as failure', ['old' => $url, 'new' => $valid_url]);
-                               self::setFailure($url);
+                               self::setFailureByUrl($url);
                                if (!self::getID($valid_url, true)) {
                                        self::detect($valid_url, $network, $only_nodeinfo);
                                }
@@ -497,7 +497,7 @@ class GServer
                                unset($parts['path']);
                                $valid_url = (string)Uri::fromParts($parts);
 
-                               self::setFailure($url);
+                               self::setFailureByUrl($url);
                                if (!self::getID($valid_url, true)) {
                                        self::detect($valid_url, $network, $only_nodeinfo);
                                }
@@ -517,7 +517,7 @@ class GServer
                // When a nodeinfo is present, we don't need to dig further
                $curlResult = DI::httpClient()->get($url . '/.well-known/x-nodeinfo2', HttpClientAccept::JSON);
                if ($curlResult->isTimeout()) {
-                       self::setFailure($url);
+                       self::setFailureByUrl($url);
                        return false;
                }
 
@@ -529,7 +529,7 @@ class GServer
 
                if ($only_nodeinfo && empty($serverdata)) {
                        Logger::info('Invalid nodeinfo in nodeinfo-mode, server is marked as failure', ['url' => $url]);
-                       self::setFailure($url);
+                       self::setFailureByUrl($url);
                        return false;
                } elseif (empty($serverdata)) {
                        $serverdata = ['detection-method' => self::DETECT_MANUAL, 'network' => Protocol::PHANTOM, 'platform' => '', 'version' => '', 'site_name' => '', 'info' => ''];
@@ -568,7 +568,7 @@ class GServer
                                }
 
                                if (!$curlResult->isSuccess() || empty($curlResult->getBody())) {
-                                       self::setFailure($url);
+                                       self::setFailureByUrl($url);
                                        return false;
                                }
 
@@ -637,7 +637,7 @@ class GServer
 
                // Most servers aren't installed in a subdirectory, so we declare this entry as failed
                if (($serverdata['network'] == Protocol::PHANTOM) && !empty(parse_url($url, PHP_URL_PATH)) && in_array($serverdata['detection-method'], [self::DETECT_MANUAL])) {
-                       self::setFailure($url);
+                       self::setFailureByUrl($url);
                        return false;
                }
 
@@ -654,7 +654,7 @@ class GServer
                }
 
                if (($serverdata['network'] == Protocol::PHANTOM) && in_array($serverdata['detection-method'], [self::DETECT_MANUAL, self::DETECT_BODY])) {
-                       self::setFailure($url);
+                       self::setFailureByUrl($url);
                        return false;
                }
 
index bcb341de38dd197f3d84a9b54cbb6261cf84263f..0799b9ba73c0bc555f35cd4b8d471ecffff68d28 100644 (file)
@@ -43,7 +43,7 @@ class BulkDelivery
                                $delivery_failure = true;
 
                                if (!$server_failure) {
-                                       $server_failure = !GServer::reachableById($gsid);
+                                       $server_failure = !GServer::isReachableById($gsid);
                                }
                                Logger::debug('Delivery failed', ['server_failure' => $server_failure, 'post' => $post]);
                        }
index b9b9441003c57c4e1c7922988db8138af3b27d32..c6a6ae4f176930b9bfcdf2aac8eacdcca54f8c12 100644 (file)
@@ -568,9 +568,9 @@ class Notifier
                        if (empty($contact['gsid'])) {
                                $reachable = !GServer::reachable($contact);
                        } elseif (!DI::config()->get('system', 'bulk_delivery')) {
-                               $reachable = !GServer::reachableById($contact['gsid']);
+                               $reachable = !GServer::isReachableById($contact['gsid']);
                        } else {
-                               $reachable = !GServer::defunct($contact['gsid']);
+                               $reachable = !GServer::isDefunctById($contact['gsid']);
                        }
 
                        if (!$reachable) {
index d180f34c45ef55ce5fb7b7b904b658a4651faeff..4142a08b784728bb784fc2b43d2dc6bd92e38dea 100644 (file)
@@ -43,18 +43,18 @@ class UpdateGServer
 
                $filtered = filter_var($server_url, FILTER_SANITIZE_URL);
                if (substr(Strings::normaliseLink($filtered), 0, 7) != 'http://') {
-                       GServer::setFailure($server_url);
+                       GServer::setFailureByUrl($server_url);
                        return;
                }
 
                if (($filtered != $server_url) && DBA::exists('gserver', ['nurl' => Strings::normaliseLink($server_url)])) {
-                       GServer::setFailure($server_url);
+                       GServer::setFailureByUrl($server_url);
                        return;
                }
 
                $cleaned = GServer::cleanURL($server_url);
                if (($cleaned != $server_url) && DBA::exists('gserver', ['nurl' => Strings::normaliseLink($server_url)])) {
-                       GServer::setFailure($server_url);
+                       GServer::setFailureByUrl($server_url);
                        return;
                }
 
index c45daede803b4b57f82fb26b19bab5a20c5377fb..cf6131c2e1667b74221cf6166836156e21dabdfd 100644 (file)
@@ -641,11 +641,11 @@ return [
        "delivery-queue" => [
                "comment" => "Delivery data for posts for the batch processing",
                "fields" => [
-                       "gsid" => ["type" => "int unsigned", "not null" => "1", "primary" => "1", "foreign" => ["gserver" => "id", "on delete" => "restrict"], "comment" => "Global Server ID"],
-                       "uri-id" => ["type" => "int unsigned", "not null" => "1", "primary" => "1", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table entry that contains the item uri"],
+                       "gsid" => ["type" => "int unsigned", "not null" => "1", "primary" => "1", "foreign" => ["gserver" => "id", "on delete" => "restrict"], "comment" => "Target server"],
+                       "uri-id" => ["type" => "int unsigned", "not null" => "1", "primary" => "1", "foreign" => ["item-uri" => "id"], "comment" => "Delivered post"],
                        "created" => ["type" => "datetime", "comment" => ""],
                        "command" => ["type" => "varbinary(32)", "comment" => ""],
-                       "cid" => ["type" => "int unsigned", "foreign" => ["contact" => "id"], "comment" => "contact_id (ID of the contact in contact table)"],
+                       "cid" => ["type" => "int unsigned", "foreign" => ["contact" => "id"], "comment" => "Target contact"],
                        "uid" => ["type" => "mediumint unsigned", "foreign" => ["user" => "uid"], "comment" => "Delivering user"],
                        "failed" => ["type" => "tinyint", "default" => 0, "comment" => "Number of times the delivery has failed"],
                ],