From e2e3c1cdcd8b3bf9bf571e641784137462a76301 Mon Sep 17 00:00:00 2001 From: Alexei Sorokin Date: Wed, 10 Jun 2020 13:26:06 +0300 Subject: [PATCH] [CORE] Another fix for the inboxnoticestream query --- lib/inboxnoticestream.php | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/lib/inboxnoticestream.php b/lib/inboxnoticestream.php index c8b5ccd7af..1cf044be27 100644 --- a/lib/inboxnoticestream.php +++ b/lib/inboxnoticestream.php @@ -107,19 +107,26 @@ class RawInboxNoticeStream extends FullNoticeStream $notice->whereAdd(sprintf('notice.created > "%s"', $notice->escape($this->target->created))); // Reply:: is a table of mentions // Subscription:: is a table of subscriptions (every user is subscribed to themselves) - // Sort in descending order as id will give us even really old posts, - // which were recently imported. For example, if a remote instance had - // problems and just managed to post here. - $notice->whereAdd( - sprintf('id IN (SELECT DISTINCT id FROM (' . - '(SELECT id FROM notice WHERE profile_id IN (SELECT subscribed FROM subscription WHERE subscriber = %1$d)) UNION ' . - '(SELECT notice_id AS id FROM reply WHERE profile_id = %1$d) UNION ' . - '(SELECT notice_id AS id FROM attention WHERE profile_id = %1$d) UNION ' . - '(SELECT notice_id AS id FROM group_inbox WHERE group_id IN (SELECT group_id FROM group_member WHERE profile_id = %1$d)) ' . - 'ORDER BY id DESC) AS T)', - $this->target->getID()) + $notice->_join .= sprintf( + "\n" . <<<'END' + LEFT JOIN ( + SELECT id FROM notice + WHERE profile_id + IN (SELECT subscribed FROM subscription WHERE subscriber = %1$d) + UNION ALL + SELECT notice_id AS id FROM reply WHERE profile_id = %1$d + UNION ALL + SELECT notice_id AS id FROM attention WHERE profile_id = %1$d + UNION ALL + SELECT notice_id AS id FROM group_inbox INNER JOIN group_member USING (group_id) + WHERE group_member.profile_id = %1$d + ) AS t1 USING (id) + END, + $this->target->getID() ); + $notice->whereAdd('t1.id IS NOT NULL'); + if (!empty($since_id)) { $notice->whereAdd(sprintf('notice.id > %d', $since_id)); } @@ -129,6 +136,11 @@ class RawInboxNoticeStream extends FullNoticeStream self::filterVerbs($notice, $this->selectVerbs); + // notice.id will give us even really old posts, which were recently + // imported. For example if a remote instance had problems and just + // managed to post here. + $notice->orderBy('id DESC'); + $notice->limit($offset, $limit); if (!$notice->find()) {