From b481db493cd6d66836c1ecdc481e8cd48101268c Mon Sep 17 00:00:00 2001 From: Shish Date: Wed, 23 Mar 2011 11:37:46 +0000 Subject: [PATCH] cache recent comments and comment page count --- ext/comment/main.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/ext/comment/main.php b/ext/comment/main.php index 8751fb39..635b73c6 100644 --- a/ext/comment/main.php +++ b/ext/comment/main.php @@ -152,10 +152,14 @@ class CommentList extends SimpleExtension { } public function onPostListBuilding(PostListBuildingEvent $event) { - global $config; + global $config, $database; $cc = $config->get_int("comment_count"); if($cc > 0) { - $recent = $this->get_recent_comments($cc); + $recent = $database->cache->get("recent_comments"); + if(empty($recent)) { + $recent = $this->get_recent_comments($cc); + $database->cache->set("recent_comments", $recent, 600); + } if(count($recent) > 0) { $this->theme->display_recent_comments($recent); } @@ -265,8 +269,11 @@ class CommentList extends SimpleExtension { "; $result = $database->Execute($get_threads, array("limit"=>$threads_per_page, "offset"=>$start)); - $total_pages = (int)($database->get_one("SELECT COUNT(c1) FROM (SELECT COUNT(image_id) AS c1 FROM comments GROUP BY image_id) AS s1") / 10); - + $total_pages = $database->cache->get("comment_pages"); + if(empty($total_pages)) { + $total_pages = (int)($database->get_one("SELECT COUNT(c1) FROM (SELECT COUNT(image_id) AS c1 FROM comments GROUP BY image_id) AS s1") / 10); + $database->cache->set("comment_pages", $total_pages, 600); + } $images = array(); while($row = $result->fetch()) {