functions.php: add caching to has_any_history

This commit is contained in:
Zankaria 2024-11-12 15:11:25 +01:00
parent 4277cc9851
commit ee4ba0ed26

View file

@ -925,6 +925,15 @@ function checkBan($board = false) {
* @return bool True if the ip has already sent at least one post, false otherwise.
*/
function has_any_history(string $ip): bool {
global $config;
if ($config['cache']['enabled']) {
$ret = cache::get("post_history_$ip");
if ($ret !== false) {
return $ret !== 0x0;
}
}
foreach (listBoards(true) as $board_uri) {
$query = prepare(sprintf('SELECT `id` FROM ``posts_%s`` WHERE `ip` = :ip LIMIT 1', $board_uri));
$query->bindValue(':ip', $ip);
@ -932,9 +941,15 @@ function has_any_history(string $ip): bool {
if ($query->fetchColumn() !== false) {
// Found a post.
if ($config['cache']['enabled']) {
cache::set("post_history_$ip", 0xA);
}
return true;
}
}
if ($config['cache']['enabled']) {
cache::set("post_history_$ip", 0x0);
}
return false;
}