From 0177c8f1cf5550a57e1ed3a29aff1660fdf6627d Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Tue, 29 Mar 2016 14:36:27 +0200 Subject: [PATCH] Use join instead of exists in SQL --- scripts/upgrade.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/scripts/upgrade.php b/scripts/upgrade.php index fa55cfc206..f29c9f10bf 100755 --- a/scripts/upgrade.php +++ b/scripts/upgrade.php @@ -171,9 +171,14 @@ function initConversation() printfnq("Ensuring all conversations have a row in conversation table..."); $notice = new Notice(); - $notice->query('select distinct notice.conversation from notice '. - 'where notice.conversation is not null '. - 'and not exists (select conversation.id from conversation where id = notice.conversation)'); + $notice->selectAdd(); + $notice->selectAdd('DISTINCT conversation'); + $notice->joinAdd(['conversation', 'conversation:id'], 'LEFT'); // LEFT to get the null values for conversation.id + $notice->whereAdd('conversation.id IS NULL'); + + if ($notice->find()) { + printfnq(" fixing {$notice->N} missing conversation entries..."); + } while ($notice->fetch()) { -- 2.39.5