]> git.mxchange.org Git - friendica.git/commitdiff
Don't add already queued items from Diaspora to the queue again
authorMichael <heluecht@pirati.ca>
Thu, 8 Feb 2018 11:26:24 +0000 (11:26 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 8 Feb 2018 11:26:24 +0000 (11:26 +0000)
boot.php
database.sql
src/Database/DBStructure.php
src/Model/Queue.php
src/Protocol/Diaspora.php
src/Worker/Delivery.php
src/Worker/Queue.php

index b2d9f019276462efc85f689ac24dab4ecd85e654..48c9b294440f13fa0d3bf3fd9b8d9c5e868f68e0 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -39,7 +39,7 @@ define('FRIENDICA_PLATFORM',     'Friendica');
 define('FRIENDICA_CODENAME',     'Asparagus');
 define('FRIENDICA_VERSION',      '3.6-dev');
 define('DFRN_PROTOCOL_VERSION',  '2.23');
-define('DB_UPDATE_VERSION',      1249);
+define('DB_UPDATE_VERSION',      1250);
 define('NEW_UPDATE_ROUTINE_VERSION', 1170);
 
 /**
index 85cd811c1b0ac15cf766b466f0e6f39d2aa775a7..7193b59d17a93f53f55ec3efd741705c3b1282d6 100644 (file)
@@ -1,6 +1,6 @@
 -- ------------------------------------------
 -- Friendica 3.6-dev (Asparagus)
--- DB_UPDATE_VERSION 1248
+-- DB_UPDATE_VERSION 1250
 -- ------------------------------------------
 
 
@@ -855,6 +855,7 @@ CREATE TABLE IF NOT EXISTS `queue` (
        `id` int NOT NULL auto_increment COMMENT '',
        `cid` int NOT NULL DEFAULT 0 COMMENT '',
        `network` varchar(32) NOT NULL DEFAULT '' COMMENT '',
+       `guid` varchar(255) NOT NULL DEFAULT '' COMMENT '',
        `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
        `last` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
        `content` mediumtext COMMENT '',
index 4c05782f178b118ef94d69fc5b65439f2ed49bcd..4cf96db260bf3491e63295acd4228b5e279a5a0b 100644 (file)
@@ -1551,6 +1551,7 @@ class DBStructure
                                                "id" => ["type" => "int", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => ""],
                                                "cid" => ["type" => "int", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => ""],
                                                "network" => ["type" => "varchar(32)", "not null" => "1", "default" => "", "comment" => ""],
+                                               "guid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
                                                "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
                                                "last" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
                                                "content" => ["type" => "mediumtext", "comment" => ""],
index 3c3cf379a4901497bb5d74fd6e04a89d1f57875b..2d7873a1e054160554aaf645ee286841afaf7339 100644 (file)
@@ -66,7 +66,7 @@ class Queue
         * @param string  $msg     message
         * @param boolean $batch   batch, default false
         */
-       public static function add($cid, $network, $msg, $batch = false)
+       public static function add($cid, $network, $msg, $batch = false, $guid = '')
        {
 
                $max_queue = Config::get('system', 'max_contact_queue');
@@ -86,10 +86,10 @@ class Queue
 
                if (DBM::is_result($r)) {
                        if ($batch &&  ($r[0]['total'] > $batch_queue)) {
-                               logger('add_to_queue: too many queued items for batch server ' . $cid . ' - discarding message');
+                               logger('too many queued items for batch server ' . $cid . ' - discarding message');
                                return;
                        } elseif ((! $batch) && ($r[0]['total'] > $max_queue)) {
-                               logger('add_to_queue: too many queued items for contact ' . $cid . ' - discarding message');
+                               logger('too many queued items for contact ' . $cid . ' - discarding message');
                                return;
                        }
                }
@@ -97,10 +97,12 @@ class Queue
                dba::insert('queue', [
                        'cid'     => $cid,
                        'network' => $network,
+                       'guid'     => $guid,
                        'created' => DateTimeFormat::utcNow(),
                        'last'    => DateTimeFormat::utcNow(),
                        'content' => $msg,
                        'batch'   =>($batch) ? 1 : 0
                ]);
+               logger('Added item ' . $guid . ' for ' . $cid);
        }
 }
index 0f5c9c0c9ddac10987b25963cc6eb682126c81df..534f6ed6ba241d9e34dfbdd72404544c6af1e878 100644 (file)
@@ -3181,7 +3181,7 @@ class Diaspora
         *
         * @return int Result of the transmission
         */
-       public static function transmit($owner, $contact, $envelope, $public_batch, $queue_run = false, $guid = "")
+       public static function transmit($owner, $contact, $envelope, $public_batch, $queue_run = false, $guid = "", $no_queue = false)
        {
                $a = get_app();
 
@@ -3224,24 +3224,14 @@ class Diaspora
                logger("transmit: ".$logid."-".$guid." returns: ".$return_code);
 
                if (!$return_code || (($return_code == 503) && (stristr($a->get_curl_headers(), "retry-after")))) {
-                       logger("queue message");
-
-                       $r = q(
-                               "SELECT `id` FROM `queue` WHERE `cid` = %d AND `network` = '%s' AND `content` = '%s' AND `batch` = %d LIMIT 1",
-                               intval($contact["id"]),
-                               dbesc(NETWORK_DIASPORA),
-                               dbesc($envelope),
-                               intval($public_batch)
-                       );
-                       if ($r) {
-                               logger("add_to_queue ignored - identical item already in queue");
-                       } else {
+                       if (!$no_queue) {
+                               logger("queue message");
                                // queue message for redelivery
-                               Queue::add($contact["id"], NETWORK_DIASPORA, $envelope, $public_batch);
-
-                               // The message could not be delivered. We mark the contact as "dead"
-                               Contact::markForArchival($contact);
+                               Queue::add($contact["id"], NETWORK_DIASPORA, $envelope, $public_batch, $guid);
                        }
+
+                       // The message could not be delivered. We mark the contact as "dead"
+                       Contact::markForArchival($contact);
                } elseif (($return_code >= 200) && ($return_code <= 299)) {
                        // We successfully delivered a message, the contact is alive
                        Contact::unmarkForArchival($contact);
@@ -3294,7 +3284,7 @@ class Diaspora
                $envelope = self::buildMessage($msg, $owner, $contact, $owner['uprvkey'], $contact['pubkey'], $public_batch);
 
                if ($spool) {
-                       Queue::add($contact['id'], NETWORK_DIASPORA, $envelope, $public_batch);
+                       Queue::add($contact['id'], NETWORK_DIASPORA, $envelope, $public_batch, $guid);
                        return true;
                } else {
                        $return_code = self::transmit($owner, $contact, $envelope, $public_batch, false, $guid);
index 0a77f7b5be18b4d26848fe718f633139df2a7bad..2b9a00176e658d442cd45aa6397046315d7e331b 100644 (file)
@@ -322,7 +322,7 @@ class Delivery {
 
                                if ($deliver_status < 0) {
                                        logger('notifier: delivery failed: queuing message');
-                                       Queue::add($contact['id'], NETWORK_DFRN, $atom);
+                                       Queue::add($contact['id'], NETWORK_DFRN, $atom, false, $target_item['guid']);
 
                                        // The message could not be delivered. We mark the contact as "dead"
                                        Contact::markForArchival($contact);
index 10a83e5c4bf0be0ca2414002909554bb93538146..f44be4918c41cb25592a83a9b756b0ba8064b468 100644 (file)
@@ -145,7 +145,7 @@ class Queue
                        case NETWORK_DIASPORA:
                                if ($contact['notify']) {
                                        logger('queue: diaspora_delivery: item ' . $q_item['id'] . ' for ' . $contact['name'] . ' <' . $contact['url'] . '>');
-                                       $deliver_status = Diaspora::transmit($owner, $contact, $data, $public, true);
+                                       $deliver_status = Diaspora::transmit($owner, $contact, $data, $public, true, 'Queue:' . $q_item['id'], true);
 
                                        if ($deliver_status == (-1)) {
                                                QueueModel::updateTime($q_item['id']);