]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
New mechanism for "all" feed (InboxNoticeStream)
authorMikael Nordfeldth <mmn@hethane.se>
Thu, 6 Mar 2014 02:43:48 +0000 (03:43 +0100)
committerMikael Nordfeldth <mmn@hethane.se>
Thu, 6 Mar 2014 03:18:54 +0000 (04:18 +0100)
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
actions/allrss.php
actions/apitimelinefriends.php
lib/inboxnoticestream.php
lib/inboxtagcloudsection.php
plugins/EmailSummary/lib/useremailsummaryhandler.php
plugins/Mapstraction/actions/allmap.php
scripts/createsim.php

index f794064f877d14d9b2f73b1eabe7bbe3cc500edc..a0e0b9a08b71a59ff2c4e7a7ba19f6cd922361b3 100644 (file)
@@ -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));
     }
 }
index 3db19ffdcce54e0e615a828ef8e80d0b73960d1c..637352bf4b32f28da288f0a147dea703c48d80cd 100644 (file)
@@ -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();
index 9a0221b1a2abc17f0550fa8a7bc4b6c5e83dc6fb..b14635ac33e5fcf6662d05f7d79f098639476317 100644 (file)
@@ -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,
index 913e9fff2e85e685feb95b1e9709810d523ee9ae..0eb791d70a45823a140629e235b20b75d4ccf26f 100644 (file)
@@ -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;
     }
index 51424c5939e24a1c64623db1d198fee94ba5c5b8..05c688fc14eca432cf88bbdb5ad998dd5ebcd6f5 100644 (file)
@@ -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);
 
index 01f6ca826424425804f2ed452d92cfdb18cda709..e35fdf796804a2a0bf2684fd7d3e299d5d23342e 100644 (file)
@@ -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);
 
index d1a9fddabb467b269cf647eed081c80ebd65fb7e..21bdf62eaa94594a5c7615e3dcaa46ddcc61f09c 100644 (file)
@@ -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,
index 7fc2ed1d90f1ce86762361aa5d06807f838a4ca6..afd46b9c6e9dd17163b94fdb6bb6735a6c5396c2 100644 (file)
@@ -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);