]> git.mxchange.org Git - friendica.git/commitdiff
Use a combined unique index
authorMichael <heluecht@pirati.ca>
Wed, 2 Dec 2020 00:34:10 +0000 (00:34 +0000)
committerMichael <heluecht@pirati.ca>
Wed, 2 Dec 2020 00:34:10 +0000 (00:34 +0000)
database.sql
src/Model/Post/Delayed.php
src/Protocol/Feed.php
static/dbstructure.config.php

index 520c5e9b054e6f5f043fa8145424837d1cea1512..99053884d85032f6ca642d70bfafbcf38990adf0 100644 (file)
@@ -470,7 +470,7 @@ CREATE TABLE IF NOT EXISTS `delayed-post` (
        `uid` mediumint unsigned COMMENT 'Owner User id',
        `delayed` datetime COMMENT 'delay time',
         PRIMARY KEY(`id`),
-        UNIQUE INDEX `uri` (`uri`(190)),
+        UNIQUE INDEX `uid_uri` (`uid`,`uri`(190)),
        FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Posts that are about to be posted at a later time';
 
index 963122b5b83eba98a070553b962bbca124339ca9..a29d05422afc7cc9672d5fd294ee5fc9f0f23479 100644 (file)
@@ -42,7 +42,7 @@ class Delayed
         */ 
        public static function add(string $delayed, array $item, int $notify = 0, array $taglist = [], array $attachments = [])
        {
-               if (empty($item['uri']) || empty($item['uid']) || self::exists($item['uri'])) {
+               if (empty($item['uri']) || empty($item['uid']) || self::exists($item['uri'], $item['uid'])) {
                        return false;
                }
 
@@ -59,9 +59,9 @@ class Delayed
         *
         * @return bool delete success
         */
-       private static function delete(string $uri)
+       private static function delete(string $uri, int $uid)
        {
-               return DBA::delete('delayed-post', ['uri' => $uri]);
+               return DBA::delete('delayed-post', ['uri' => $uri, 'uid' => $uid]);
        }
 
        /**
@@ -71,9 +71,9 @@ class Delayed
         *
         * @return bool "true" if an entry with that URI exists
         */
-       public static function exists(string $uri)
+       public static function exists(string $uri, int $uid)
        {
-               return DBA::exists('delayed-post', ['uri' => $uri]);
+               return DBA::exists('delayed-post', ['uri' => $uri, 'uid' => $uid]);
        }
 
        /**
@@ -93,7 +93,7 @@ class Delayed
 
                // It should always contain an URI since this is needed to create a delayed post entry
                if (!empty($item['uri'])) {
-                       $result = self::delete($item['uri']);
+                       $result = self::delete($item['uri'], $item['uid']);
                        Logger::notice('Delayed post entry deleted', ['result' => $result, 'uri' => $item['uri']]);
                }
 
index 48677a91b7aedb5a418a66a93053f61e65999dd2..ed24defc2e3fe20e55f412685b14b0f60152a60d 100644 (file)
@@ -615,7 +615,7 @@ class Feed
                        }
 
                        $condition = ['uid' => $item['uid'], 'uri' => $item['uri']];
-                       if (!Item::exists($condition) && !Post\Delayed::exists($item["uri"])) {
+                       if (!Item::exists($condition) && !Post\Delayed::exists($item["uri"], $item['uid'])) {
                                $postings[] = ['item' => $item, 'notify' => $notify,
                                        'taglist' => $taglist, 'attachments' => $attachments];
                        } else {
index 9af9c46257c7ad24fbaa52dec93abddb5a26336e..106ae4e3f00f9cde5e6921228f9ebfb037c9ec6b 100644 (file)
@@ -537,7 +537,7 @@ return [
                ],
                "indexes" => [
                        "PRIMARY" => ["id"],
-                       "uri" => ["UNIQUE", "uri(190)"],
+                       "uid_uri" => ["UNIQUE", "uid", "uri(190)"],
                ]
        ],
        "diaspora-interaction" => [