From 4b2a66ed29091209c05d74755e42f96265c846ce Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Thu, 6 Mar 2014 03:43:48 +0100 Subject: [PATCH] New mechanism for "all" feed (InboxNoticeStream) Also cleaned up and made typing stricter for the stream, so only profiles can be submitted. This reasonably also means we can create "inbox" or "all" streams for foreign profiles as well using the same stream handler (but of course only for messages we already know about). To avoid looking up posts for a long time in a large notice database, the lookback period for the inbox is no longer than the profile creation date. (this matches the behaviour of Inbox) Inbox class can probably be removed now. --- actions/all.php | 6 +++--- actions/allrss.php | 2 +- actions/apitimelinefriends.php | 2 +- lib/inboxnoticestream.php | 17 ++++++++++------- lib/inboxtagcloudsection.php | 10 +++++----- .../lib/useremailsummaryhandler.php | 3 ++- plugins/Mapstraction/actions/allmap.php | 3 +-- scripts/createsim.php | 2 +- 8 files changed, 24 insertions(+), 21 deletions(-) diff --git a/actions/all.php b/actions/all.php index f794064f87..a0e0b9a08b 100644 --- a/actions/all.php +++ b/actions/all.php @@ -213,7 +213,7 @@ class AllAction extends ProfileAction // XXX: make this a little more convenient if (!common_config('performance', 'high')) { - $pop = new PopularNoticeSection($this, Profile::current()); + $pop = new PopularNoticeSection($this, $this->scoped); $pop->show(); $pop = new InboxTagCloudSection($this, $this->target); $pop->show(); @@ -223,8 +223,8 @@ class AllAction extends ProfileAction class ThreadingInboxNoticeStream extends ThreadingNoticeStream { - function __construct($user, $profile) + function __construct(Profile $target, Profile $scoped=null) { - parent::__construct(new InboxNoticeStream($user, $profile)); + parent::__construct(new InboxNoticeStream($target, $scoped)); } } diff --git a/actions/allrss.php b/actions/allrss.php index 3db19ffdcc..637352bf4b 100644 --- a/actions/allrss.php +++ b/actions/allrss.php @@ -83,7 +83,7 @@ class AllrssAction extends Rss10Action */ function getNotices($limit=0) { - $stream = new InboxNoticeStream($this->user); + $stream = new InboxNoticeStream($this->user->getProfile()); $notice = $stream->getNotices(0, $limit, null, null); $notices = array(); diff --git a/actions/apitimelinefriends.php b/actions/apitimelinefriends.php index 9a0221b1a2..b14635ac33 100644 --- a/actions/apitimelinefriends.php +++ b/actions/apitimelinefriends.php @@ -274,7 +274,7 @@ class ApiTimelineFriendsAction extends ApiBareAuthAction { $notices = array(); - $stream = new InboxNoticeStream($this->target->getUser(), $this->scoped); + $stream = new InboxNoticeStream($this->target, $this->scoped); $notice = $stream->getNotices(($this->page-1) * $this->count, $this->count, diff --git a/lib/inboxnoticestream.php b/lib/inboxnoticestream.php index 913e9fff2e..0eb791d70a 100644 --- a/lib/inboxnoticestream.php +++ b/lib/inboxnoticestream.php @@ -102,19 +102,22 @@ class RawInboxNoticeStream extends NoticeStream { $notice = new Notice(); $notice->selectAdd(); - $notice->selectAdd('notice_id'); - // Reply is a class for mentions - $notice->joinAdd(array('id', 'reply:notice_id')); - - $notice->profile_id = $this->target->id; + $notice->selectAdd('id'); + $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) + $notice->whereAdd( + sprintf('notice.id IN (SELECT notice_id FROM reply WHERE profile_id=%1$d) ' . + 'OR notice.profile_id IN (SELECT subscribed FROM subscription WHERE subscriber=%d)', $this->target->id) + ); $notice->limit($offset, $limit); - $notice->orderBy('created DESC'); + $notice->orderBy('notice.created DESC'); if (!$notice->find()) { return array(); } - $ids = $notice->fetchAll('notice_id'); + $ids = $notice->fetchAll('id'); return $ids; } diff --git a/lib/inboxtagcloudsection.php b/lib/inboxtagcloudsection.php index 51424c5939..05c688fc14 100644 --- a/lib/inboxtagcloudsection.php +++ b/lib/inboxtagcloudsection.php @@ -42,12 +42,12 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { */ class InboxTagCloudSection extends TagCloudSection { - var $user = null; + protected $target = null; - function __construct($out=null, $user=null) + function __construct($out=null, Profile $target) { parent::__construct($out); - $this->user = $user; + $this->target = $target; } function title() @@ -60,14 +60,14 @@ class InboxTagCloudSection extends TagCloudSection { $profile = Profile::current(); - $keypart = sprintf('Inbox:notice_tag:%d:%d', $this->user->id, + $keypart = sprintf('Inbox:notice_tag:%d:%d', $this->target, $profile instanceof Profile ? $profile->id : 0); $tag = Memcached_DataObject::cacheGet($keypart); if ($tag === false) { - $stream = new InboxNoticeStream($this->user, $profile); + $stream = new InboxNoticeStream($this->target, $profile); $ids = $stream->getNoticeIds(0, Inbox::MAX_NOTICES, null, null); diff --git a/plugins/EmailSummary/lib/useremailsummaryhandler.php b/plugins/EmailSummary/lib/useremailsummaryhandler.php index 01f6ca8264..e35fdf7968 100644 --- a/plugins/EmailSummary/lib/useremailsummaryhandler.php +++ b/plugins/EmailSummary/lib/useremailsummaryhandler.php @@ -102,7 +102,8 @@ class UserEmailSummaryHandler extends QueueHandler return true; } - $stream = new InboxNoticeStream($user, $user->getProfile()); + // An InboxNoticeStream for a certain user, scoped to its own view + $stream = new InboxNoticeStream($profile, $profile); $notice = $stream->getNotices(0, self::MAX_NOTICES, $since_id); diff --git a/plugins/Mapstraction/actions/allmap.php b/plugins/Mapstraction/actions/allmap.php index d1a9fddabb..21bdf62eaa 100644 --- a/plugins/Mapstraction/actions/allmap.php +++ b/plugins/Mapstraction/actions/allmap.php @@ -47,8 +47,7 @@ class AllmapAction extends MapAction function prepare($args) { if (parent::prepare($args)) { - $cur = common_current_user(); - $stream = new InboxNoticeStream($this->user, $cur->getProfile()); + $stream = new InboxNoticeStream($this->user->getProfile(), $this->scoped); $this->notice = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1, null, diff --git a/scripts/createsim.php b/scripts/createsim.php index 7fc2ed1d90..afd46b9c6e 100644 --- a/scripts/createsim.php +++ b/scripts/createsim.php @@ -95,7 +95,7 @@ function newNotice($i, $tagmax) $content = testNoticeContent(); if ($is_reply == 0) { - $stream = new InboxNoticeStream($user, $user->getProfile()); + $stream = new InboxNoticeStream($user->getProfile(), $user->getProfile()); $notices = $stream->getNotices(0, 20); if ($notices->N > 0) { $nval = rand(0, $notices->N - 1); -- 2.39.5