diff options
| author | Michael Save <savetheinternet@tinyboard.org> | 2012-05-20 19:06:27 +1000 |
|---|---|---|
| committer | Michael Save <savetheinternet@tinyboard.org> | 2012-05-20 19:06:27 +1000 |
| commit | 0f041170372b9dfcba7645d8b05066867c0d3f75 (patch) | |
| tree | b83c43c97b59fba50fc7e9e042fefdb23f6a90e3 /inc/mod/auth.php | |
| parent | d6a1f16555376fc4b57a572e21758a400db8852a (diff) | |
Cache unread PM notices
Diffstat (limited to 'inc/mod/auth.php')
| -rw-r--r-- | inc/mod/auth.php | 25 |
1 files changed, 20 insertions, 5 deletions
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; } |
