From 503a5be06c109c71fa5bf5a1c3e18695e4529771 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 29 Aug 2019 06:55:36 +0200 Subject: [PATCH] Fixed query (not all duplicates had been found) --- src/Database/PostUpdate.php | 8 +++++--- src/Model/Contact.php | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Database/PostUpdate.php b/src/Database/PostUpdate.php index 76ec3ea01..651766fcf 100644 --- a/src/Database/PostUpdate.php +++ b/src/Database/PostUpdate.php @@ -434,10 +434,12 @@ class PostUpdate Logger::info('Start'); - $contacts = DBA::p("SELECT ANY_VALUE(`id`) AS `id` FROM `contact` + $contacts = DBA::p("SELECT ANY_VALUE(`id`) AS `id`, ANY_VALUE(`nurl`) AS `nurl` FROM `contact` WHERE EXISTS (SELECT `nurl` FROM `contact` AS `c2` - WHERE `c2`.`nurl` = `contact`.`nurl` AND `c2`.`id` != `contact`.`id` AND `c2`.`uid` = `contact`.`uid` AND `c2`.`network` = `contact`.`network`) - AND `network` IN (?, ?, ?) GROUP BY `nurl`", Protocol::DIASPORA, Protocol::OSTATUS, Protocol::ACTIVITYPUB); + WHERE `c2`.`nurl` = `contact`.`nurl` AND `c2`.`id` != `contact`.`id` AND `c2`.`uid` = `contact`.`uid` AND `c2`.`network` IN (?, ?, ?)) + AND (`network` IN (?, ?, ?) OR (`uid` = ?)) GROUP BY `nurl`, `uid`", + Protocol::DIASPORA, Protocol::OSTATUS, Protocol::ACTIVITYPUB, + Protocol::DIASPORA, Protocol::OSTATUS, Protocol::ACTIVITYPUB, 0); while ($contact = DBA::fetch($contacts)) { Logger::info('Remove duplicates', ['id' => $contact['id']]); diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 49d4e4cc6..ca3ac4411 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -1929,13 +1929,13 @@ class Contact extends BaseObject { $contact = DBA::selectFirst('contact', ['nurl', 'uid', 'id'], ['id' => $contact_id]); if (!DBA::isResult($contact)) { - return $ret; + return; } // Search for duplicated contacts and get rid of them self::handleDuplicates($contact['nurl'], $contact['uid'], $contact['id']); - return $ret; + return; } /**