]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
cache the notice count for threaded view
authorEvan Prodromou <evan@status.net>
Thu, 7 Apr 2011 03:17:17 +0000 (23:17 -0400)
committerEvan Prodromou <evan@status.net>
Thu, 7 Apr 2011 03:17:17 +0000 (23:17 -0400)
classes/Conversation.php
classes/Notice.php
lib/threadednoticelist.php

index aab55723f644188720268fb4076629ab4e8d417f..e029c20ba0d095145cff147b35aaec6f49d5dd5b 100755 (executable)
@@ -74,4 +74,23 @@ class Conversation extends Memcached_DataObject
 
         return $conv;
     }
+
+    static function noticeCount($id)
+    {
+        $keypart = sprintf('conversation:notice_count:%d', $id);
+
+        $cnt = self::cacheGet($keypart);
+
+        if ($cnt !== false) {
+            return $cnt;
+        }
+
+        $notice               = new Notice();
+        $notice->conversation = $id;
+        $cnt                  = $notice->count();
+
+        self::cacheSet($keypart, $cnt);
+
+        return $cnt;
+    }
 }
index 8098a8ace845c8cbf1d71011601ad19ab2ba59c0..763547a0e17ac09487150cac586ba9bd5e8c1f6f 100644 (file)
@@ -567,6 +567,7 @@ class Notice extends Memcached_DataObject
         // was not the root of the conversation.  What to do now?
 
         self::blow('notice:conversation_ids:%d', $this->conversation);
+        self::blow('conversation::notice_count:%d', $this->conversation);
 
         if (!empty($this->repeat_of)) {
             self::blow('notice:repeats:%d', $this->repeat_of);
index 700b6ed1eea03455c13e362a9634cc6dd5f5d36e..b686e17629e55d7479a0305b929ec7ef19906d39 100644 (file)
@@ -284,9 +284,8 @@ class ThreadedNoticeListMoreItem extends NoticeListItem
         $id = $this->notice->conversation;
         $url = common_local_url('conversationreplies', array('id' => $id));
 
-        $notice = new Notice();
-        $notice->conversation = $id;
-        $n = $notice->count() - 1;
+        $n = Conversation::noticeCount($id) - 1;
+
         // TRANS: Link to show replies for a notice.
         // TRANS: %d is the number of replies to a notice and used for plural.
         $msg = sprintf(_m('Show reply', 'Show all %d replies', $n), $n);