mirror of
https://github.com/vichan-devel/vichan.git
synced 2025-01-30 11:57:28 +01:00
Cache unread PM notices
This commit is contained in:
parent
5a0a317101
commit
5767954841
@ -48,7 +48,7 @@ class Cache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// debug
|
// debug
|
||||||
if ($data && $config['debug']) {
|
if ($data !== false && $config['debug']) {
|
||||||
$debug['cached'][] = $key;
|
$debug['cached'][] = $key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,6 @@
|
|||||||
$config['check_updates_time'] = 43200; // 12 hours
|
$config['check_updates_time'] = 43200; // 12 hours
|
||||||
|
|
||||||
// Shows some extra information at the bottom of pages. Good for debugging development.
|
// Shows some extra information at the bottom of pages. Good for debugging development.
|
||||||
// Also experimental.
|
|
||||||
$config['debug'] = false;
|
$config['debug'] = false;
|
||||||
// For development purposes. Turns 'display_errors' on. Not recommended for production.
|
// For development purposes. Turns 'display_errors' on. Not recommended for production.
|
||||||
$config['verbose_errors'] = true;
|
$config['verbose_errors'] = true;
|
||||||
|
@ -123,15 +123,30 @@ if (isset($_COOKIE[$config['cookies']['mod']])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function create_pm_header() {
|
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 = prepare("SELECT `id` FROM `pms` WHERE `to` = :id AND `unread` = 1");
|
||||||
$query->bindValue(':id', $mod['id'], PDO::PARAM_INT);
|
$query->bindValue(':id', $mod['id'], PDO::PARAM_INT);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
if ($pm = $query->fetch()) {
|
if ($pm = $query->fetch())
|
||||||
return Array('id' => $pm['id'], 'waiting' => $query->rowCount() - 1);
|
$header = Array('id' => $pm['id'], 'waiting' => $query->rowCount() - 1);
|
||||||
}
|
else
|
||||||
|
$header = true;
|
||||||
|
|
||||||
return false;
|
if ($config['cache']['enabled'])
|
||||||
|
cache::set('pm_unread_' . $mod['id'], $header);
|
||||||
|
|
||||||
|
if ($header === true)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return $header;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,10 +88,15 @@ function mod_dashboard() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = prepare('SELECT COUNT(*) FROM `pms` WHERE `to` = :id AND `unread` = 1');
|
if (!$config['cache']['enabled'] || ($args['unread_pms'] = cache::get('pm_unreadcount_' . $mod['id'])) === false) {
|
||||||
$query->bindValue(':id', $mod['id']);
|
$query = prepare('SELECT COUNT(*) FROM `pms` WHERE `to` = :id AND `unread` = 1');
|
||||||
$query->execute() or error(db_error($query));
|
$query->bindValue(':id', $mod['id']);
|
||||||
$args['unread_pms'] = $query->fetchColumn(0);
|
$query->execute() or error(db_error($query));
|
||||||
|
$args['unread_pms'] = $query->fetchColumn(0);
|
||||||
|
|
||||||
|
if ($config['cache']['enabled'])
|
||||||
|
cache::set('pm_unreadcount_' . $mod['id'], $args['unread_pms']);
|
||||||
|
}
|
||||||
|
|
||||||
if ($mod['type'] >= ADMIN && $config['check_updates']) {
|
if ($mod['type'] >= ADMIN && $config['check_updates']) {
|
||||||
if (!$config['version'])
|
if (!$config['version'])
|
||||||
@ -1247,6 +1252,11 @@ function mod_pm($id, $reply = false) {
|
|||||||
$query->bindValue(':id', $id);
|
$query->bindValue(':id', $id);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
|
if ($config['cache']['enabled']) {
|
||||||
|
cache::delete('pm_unread_' . $mod['id']);
|
||||||
|
cache::delete('pm_unreadcount_' . $mod['id']);
|
||||||
|
}
|
||||||
|
|
||||||
header('Location: ?/', true, $config['redirect_http']);
|
header('Location: ?/', true, $config['redirect_http']);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1256,6 +1266,11 @@ function mod_pm($id, $reply = false) {
|
|||||||
$query->bindValue(':id', $id);
|
$query->bindValue(':id', $id);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
|
if ($config['cache']['enabled']) {
|
||||||
|
cache::delete('pm_unread_' . $mod['id']);
|
||||||
|
cache::delete('pm_unreadcount_' . $mod['id']);
|
||||||
|
}
|
||||||
|
|
||||||
modLog('Read a PM');
|
modLog('Read a PM');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1325,6 +1340,11 @@ function mod_new_pm($username) {
|
|||||||
$query->bindValue(':time', time());
|
$query->bindValue(':time', time());
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
|
if ($config['cache']['enabled']) {
|
||||||
|
cache::delete('pm_unread_' . $id);
|
||||||
|
cache::delete('pm_unreadcount_' . $id);
|
||||||
|
}
|
||||||
|
|
||||||
modLog('Sent a PM to ' . utf8tohtml($username));
|
modLog('Sent a PM to ' . utf8tohtml($username));
|
||||||
|
|
||||||
header('Location: ?/', true, $config['redirect_http']);
|
header('Location: ?/', true, $config['redirect_http']);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user