diff --git a/inc/mod/pages.php b/inc/mod/pages.php index dc870b79..1bbe60d0 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -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 {$ip}"); 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);