forked from leftypol/leftypol
functions.php: add caching to has_any_history
This commit is contained in:
parent
4277cc9851
commit
ee4ba0ed26
1 changed files with 15 additions and 0 deletions
|
@ -925,6 +925,15 @@ function checkBan($board = false) {
|
||||||
* @return bool True if the ip has already sent at least one post, false otherwise.
|
* @return bool True if the ip has already sent at least one post, false otherwise.
|
||||||
*/
|
*/
|
||||||
function has_any_history(string $ip): bool {
|
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) {
|
foreach (listBoards(true) as $board_uri) {
|
||||||
$query = prepare(sprintf('SELECT `id` FROM ``posts_%s`` WHERE `ip` = :ip LIMIT 1', $board_uri));
|
$query = prepare(sprintf('SELECT `id` FROM ``posts_%s`` WHERE `ip` = :ip LIMIT 1', $board_uri));
|
||||||
$query->bindValue(':ip', $ip);
|
$query->bindValue(':ip', $ip);
|
||||||
|
@ -932,9 +941,15 @@ function has_any_history(string $ip): bool {
|
||||||
|
|
||||||
if ($query->fetchColumn() !== false) {
|
if ($query->fetchColumn() !== false) {
|
||||||
// Found a post.
|
// Found a post.
|
||||||
|
if ($config['cache']['enabled']) {
|
||||||
|
cache::set("post_history_$ip", 0xA);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ($config['cache']['enabled']) {
|
||||||
|
cache::set("post_history_$ip", 0x0);
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue