forked from leftypol/leftypol
pages.php: add a basic cache layer for mod_page_ip
This commit is contained in:
parent
22a8eae666
commit
52759954c8
1 changed files with 28 additions and 14 deletions
|
@ -897,15 +897,18 @@ function mod_page_ip($ip) {
|
||||||
$query->bindValue(':body', $_POST['note']);
|
$query->bindValue(':body', $_POST['note']);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
|
Cache::delete("mod_page_ip_view_notes_$ip");
|
||||||
|
|
||||||
modLog("Added a note for <a href=\"?/IP/{$ip}\">{$ip}</a>");
|
modLog("Added a note for <a href=\"?/IP/{$ip}\">{$ip}</a>");
|
||||||
|
|
||||||
header('Location: ?/IP/' . $ip . '#notes', true, $config['redirect_http']);
|
header('Location: ?/IP/' . $ip . '#notes', true, $config['redirect_http']);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$args = array();
|
$args = [
|
||||||
$args['ip'] = $ip;
|
'ip' => $ip,
|
||||||
$args['posts'] = array();
|
'posts' => []
|
||||||
|
];
|
||||||
|
|
||||||
if ($config['mod']['dns_lookup'])
|
if ($config['mod']['dns_lookup'])
|
||||||
$args['hostname'] = rDNS($ip);
|
$args['hostname'] = rDNS($ip);
|
||||||
|
@ -927,8 +930,9 @@ function mod_page_ip($ip) {
|
||||||
$po = new Post($post, '?/', $mod);
|
$po = new Post($post, '?/', $mod);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($args['posts'][$board['uri']]))
|
if (!isset($args['posts'][$board['uri']])) {
|
||||||
$args['posts'][$board['uri']] = array('board' => $board, 'posts' => array());
|
$args['posts'][$board['uri']] = [ 'board' => $board, 'posts' => [] ];
|
||||||
|
}
|
||||||
$args['posts'][$board['uri']]['posts'][] = $po->build(true);
|
$args['posts'][$board['uri']]['posts'][] = $po->build(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -941,19 +945,29 @@ function mod_page_ip($ip) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasPermission($config['mod']['view_notes'])) {
|
if (hasPermission($config['mod']['view_notes'])) {
|
||||||
|
$ret = Cache::get("mod_page_ip_view_notes_$ip");
|
||||||
|
if (!$ret) {
|
||||||
$query = prepare("SELECT ``ip_notes``.*, `username` FROM ``ip_notes`` LEFT JOIN ``mods`` ON `mod` = ``mods``.`id` WHERE `ip` = :ip ORDER BY `time` DESC");
|
$query = prepare("SELECT ``ip_notes``.*, `username` FROM ``ip_notes`` LEFT JOIN ``mods`` ON `mod` = ``mods``.`id` WHERE `ip` = :ip ORDER BY `time` DESC");
|
||||||
$query->bindValue(':ip', $ip);
|
$query->bindValue(':ip', $ip);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
$args['notes'] = $query->fetchAll(PDO::FETCH_ASSOC);
|
$ret = $query->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
Cache::set("mod_page_ip_view_notes_$ip", $ret, 900);
|
||||||
|
}
|
||||||
|
$args['notes'] = $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasPermission($config['mod']['modlog_ip'])) {
|
if (hasPermission($config['mod']['modlog_ip'])) {
|
||||||
|
$ret = Cache::get("mod_page_ip_modlog_ip_$ip");
|
||||||
|
if (!$ret) {
|
||||||
$query = prepare("SELECT `username`, `mod`, `ip`, `board`, `time`, `text` FROM ``modlogs`` LEFT JOIN ``mods`` ON `mod` = ``mods``.`id` WHERE `text` LIKE :search ORDER BY `time` DESC LIMIT 50");
|
$query = prepare("SELECT `username`, `mod`, `ip`, `board`, `time`, `text` FROM ``modlogs`` LEFT JOIN ``mods`` ON `mod` = ``mods``.`id` WHERE `text` LIKE :search ORDER BY `time` DESC LIMIT 50");
|
||||||
$query->bindValue(':search', '%' . $ip . '%');
|
$query->bindValue(':search', '%' . $ip . '%');
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
$args['logs'] = $query->fetchAll(PDO::FETCH_ASSOC);
|
$ret = $query->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
Cache::set("mod_page_ip_modlog_ip_$ip", $ret, 900);
|
||||||
|
}
|
||||||
|
$args['logs'] = $ret;
|
||||||
} else {
|
} else {
|
||||||
$args['logs'] = array();
|
$args['logs'] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$args['security_token'] = make_secure_link_token('IP/' . $ip);
|
$args['security_token'] = make_secure_link_token('IP/' . $ip);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue