From: Evan Prodromou Date: Thu, 7 Apr 2011 03:17:17 +0000 (-0400) Subject: cache the notice count for threaded view X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=59d0e2f37335345d62cd558d6804fc38b3b810c2;p=quix0rs-gnu-social.git cache the notice count for threaded view --- diff --git a/classes/Conversation.php b/classes/Conversation.php index aab55723f6..e029c20ba0 100755 --- a/classes/Conversation.php +++ b/classes/Conversation.php @@ -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; + } } diff --git a/classes/Notice.php b/classes/Notice.php index 8098a8ace8..763547a0e1 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -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); diff --git a/lib/threadednoticelist.php b/lib/threadednoticelist.php index 700b6ed1ee..b686e17629 100644 --- a/lib/threadednoticelist.php +++ b/lib/threadednoticelist.php @@ -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);