]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Use cached sources for favorites & repeats info on threaded notice lists
authorBrion Vibber <brion@pobox.com>
Fri, 18 Mar 2011 00:06:04 +0000 (17:06 -0700)
committerBrion Vibber <brion@pobox.com>
Fri, 18 Mar 2011 00:06:04 +0000 (17:06 -0700)
classes/Fave.php
classes/Notice.php
lib/threadednoticelist.php

index 4a9cfaae06a0ee7ab880ddd5314531fe077ffcf4..e4e00d27ca386712a7f32a861085fd9ebf07c843 100644 (file)
@@ -44,6 +44,7 @@ class Fave extends Memcached_DataObject
                 common_log_db_error($fave, 'INSERT', __FILE__);
                 return false;
             }
+            self::blow('fave:by_notice', $fave->notice_id);
 
             Event::handle('EndFavorNotice', array($profile, $notice));
         }
@@ -61,6 +62,7 @@ class Fave extends Memcached_DataObject
         if (Event::handle('StartDisfavorNotice', array($profile, $notice, &$result))) {
 
             $result = parent::delete();
+            self::blow('fave:by_notice', $this->notice_id);
 
             if ($result) {
                 Event::handle('EndDisfavorNotice', array($profile, $notice));
@@ -208,4 +210,31 @@ class Fave extends Memcached_DataObject
 
         return $fav;
     }
+
+    /**
+     * Grab a list of profile who have favored this notice.
+     *
+     * @return ArrayWrapper masquerading as a Fave
+     */
+    static function byNotice($noticeId)
+    {
+        $c = self::memcache();
+        $key = Cache::key('fave:by_notice', $noticeId);
+
+        $wrapper = $c->get($key);
+        if (!$wrapper) {
+            // @fixme caching & scalability!
+            $fave = new Fave();
+            $fave->notice_id = $noticeId;
+            $fave->find();
+
+            $profiles = array();
+            while ($fave->fetch()) {
+                $list[] = clone($fave);
+            }
+            $wrapper = new ArrayWrapper($list);
+            $c->set($key, $wrapper);
+        }
+        return $wrapper;
+    }
 }
index 664e5dab9f85d3c4d51901a041e7638ef285ab2b..560d45a64043cc545d798f56afde0fea2e49b60f 100644 (file)
@@ -496,6 +496,8 @@ class Notice extends Memcached_DataObject
         if ($this->isPublic()) {
             self::blow('public;last');
         }
+
+        self::blow('fave:by_notice', $this->id);
     }
 
     /** save all urls in the notice to the db
index f1f4083ed6cbf209b96adff42a379468ae3224ab..c6fe77ddb40a9b8ed63e1c2d775620a24f7ae2b5 100644 (file)
@@ -414,11 +414,7 @@ class ThreadedNoticeListFavesItem extends NoticeListActorsItem
 {
     function getProfiles()
     {
-        // @fixme caching & scalability!
-        $fave = new Fave();
-        $fave->notice_id = $this->notice->id;
-        $fave->find();
-
+        $fave = Fave::byNotice($this->notice->id);
         $profiles = array();
         while ($fave->fetch()) {
             $profiles[] = $fave->user_id;
@@ -469,10 +465,7 @@ class ThreadedNoticeListRepeatsItem extends NoticeListActorsItem
 {
     function getProfiles()
     {
-        // @fixme caching & scalability!
-        $rep = new Notice();
-        $rep->repeat_of = $this->notice->id;
-        $rep->find();
+        $rep = $this->notice->repeatStream();
 
         $profiles = array();
         while ($rep->fetch()) {