From 0f041170372b9dfcba7645d8b05066867c0d3f75 Mon Sep 17 00:00:00 2001 From: Michael Save Date: Sun, 20 May 2012 19:06:27 +1000 Subject: Cache unread PM notices --- inc/mod/auth.php | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'inc/mod/auth.php') diff --git a/inc/mod/auth.php b/inc/mod/auth.php index f9b863c8..d200c23f 100644 --- a/inc/mod/auth.php +++ b/inc/mod/auth.php @@ -123,15 +123,30 @@ if (isset($_COOKIE[$config['cookies']['mod']])) { } function create_pm_header() { - global $mod; + global $mod, $config; + + if ($config['cache']['enabled'] && ($header = cache::get('pm_unread_' . $mod['id'])) !== false) { + if ($header === true) + return false; + + return $header; + } + $query = prepare("SELECT `id` FROM `pms` WHERE `to` = :id AND `unread` = 1"); $query->bindValue(':id', $mod['id'], PDO::PARAM_INT); $query->execute() or error(db_error($query)); - if ($pm = $query->fetch()) { - return Array('id' => $pm['id'], 'waiting' => $query->rowCount() - 1); - } + if ($pm = $query->fetch()) + $header = Array('id' => $pm['id'], 'waiting' => $query->rowCount() - 1); + else + $header = true; + + if ($config['cache']['enabled']) + cache::set('pm_unread_' . $mod['id'], $header); + + if ($header === true) + return false; - return false; + return $header; } -- cgit v1.3