From 90314232789a57da554cdb913e26ad8def92a16b Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 7 May 2018 22:02:03 -0400 Subject: [PATCH] Prevent infinite push loop between multiple directories - Add auto increment id to sync-push-queue table to add new profile urls at the end - Use REPLACE instead of INSERT to prevent unique key errors --- dfrndir.sql | 4 +++- include/sync.php | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/dfrndir.sql b/dfrndir.sql index 1be9434a..07f6fa4b 100644 --- a/dfrndir.sql +++ b/dfrndir.sql @@ -190,8 +190,10 @@ CREATE TABLE IF NOT EXISTS `sync-pull-queue` ( -- CREATE TABLE IF NOT EXISTS `sync-push-queue` ( + `id` int(11) NOT NULL AUTO_INCREMENT, `url` varchar(255) CHARACTER SET utf8 NOT NULL, - PRIMARY KEY (`url`) + PRIMARY KEY (`id`), + UNIQUE KEY `url` (`url`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -- -------------------------------------------------------- diff --git a/include/sync.php b/include/sync.php index 3d816cee..b569e84a 100644 --- a/include/sync.php +++ b/include/sync.php @@ -13,7 +13,7 @@ function sync_pull($url) //If we support it that is. if ($a->config['syncing']['enable_pulling']) { - q("INSERT INTO `sync-pull-queue` (`url`) VALUES ('%s')", dbesc($url)); + q("REPLACE INTO `sync-pull-queue` (`url`) VALUES ('%s')", dbesc($url)); } } @@ -28,7 +28,7 @@ function sync_push($url) //If we support it that is. if ($a->config['syncing']['enable_pushing']) { - q("INSERT INTO `sync-push-queue` (`url`) VALUES ('%s')", dbesc($url)); + q("REPLACE INTO `sync-push-queue` (`url`) VALUES ('%s')", dbesc($url)); } sync_mark($url); @@ -96,7 +96,7 @@ function get_push_targets() */ function get_push_batch(App $a) { - return q("SELECT * FROM `sync-push-queue` LIMIT %u", intval($a->config['syncing']['max_push_items'])); + return q("SELECT * FROM `sync-push-queue` ORDER BY `id` LIMIT %u", intval($a->config['syncing']['max_push_items'])); } /**