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->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>");
|
||||
|
||||
header('Location: ?/IP/' . $ip . '#notes', true, $config['redirect_http']);
|
||||
return;
|
||||
}
|
||||
|
||||
$args = array();
|
||||
$args['ip'] = $ip;
|
||||
$args['posts'] = array();
|
||||
$args = [
|
||||
'ip' => $ip,
|
||||
'posts' => []
|
||||
];
|
||||
|
||||
if ($config['mod']['dns_lookup'])
|
||||
$args['hostname'] = rDNS($ip);
|
||||
|
@ -927,8 +930,9 @@ function mod_page_ip($ip) {
|
|||
$po = new Post($post, '?/', $mod);
|
||||
}
|
||||
|
||||
if (!isset($args['posts'][$board['uri']]))
|
||||
$args['posts'][$board['uri']] = array('board' => $board, 'posts' => array());
|
||||
if (!isset($args['posts'][$board['uri']])) {
|
||||
$args['posts'][$board['uri']] = [ 'board' => $board, 'posts' => [] ];
|
||||
}
|
||||
$args['posts'][$board['uri']]['posts'][] = $po->build(true);
|
||||
}
|
||||
}
|
||||
|
@ -941,19 +945,29 @@ function mod_page_ip($ip) {
|
|||
}
|
||||
|
||||
if (hasPermission($config['mod']['view_notes'])) {
|
||||
$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->execute() or error(db_error($query));
|
||||
$args['notes'] = $query->fetchAll(PDO::FETCH_ASSOC);
|
||||
$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->bindValue(':ip', $ip);
|
||||
$query->execute() or error(db_error($query));
|
||||
$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'])) {
|
||||
$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->execute() or error(db_error($query));
|
||||
$args['logs'] = $query->fetchAll(PDO::FETCH_ASSOC);
|
||||
$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->bindValue(':search', '%' . $ip . '%');
|
||||
$query->execute() or error(db_error($query));
|
||||
$ret = $query->fetchAll(PDO::FETCH_ASSOC);
|
||||
Cache::set("mod_page_ip_modlog_ip_$ip", $ret, 900);
|
||||
}
|
||||
$args['logs'] = $ret;
|
||||
} else {
|
||||
$args['logs'] = array();
|
||||
$args['logs'] = [];
|
||||
}
|
||||
|
||||
$args['security_token'] = make_secure_link_token('IP/' . $ip);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue