1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-24 15:40:12 +01:00

bans.php: refactor to expose the moratorium on ban deletion from the database.

Also fixes the 'purge_bans' configuration for non-cache deployments.
This commit is contained in:
Zankaria 2024-07-11 22:48:19 +02:00 committed by Zankaria
parent c057c6df29
commit ede7591702
4 changed files with 8 additions and 8 deletions

View File

@ -341,12 +341,13 @@ class Bans {
rebuildThemes('bans');
}
static public function purge($require_seen) {
static public function purge($require_seen, $moratorium) {
if ($require_seen) {
$query = prepare("DELETE FROM ``bans`` WHERE `expires` IS NOT NULL AND `expires` < :curr_time AND `seen` = 1");
$query = prepare("DELETE FROM ``bans`` WHERE `expires` IS NOT NULL AND `expires` + :moratorium < :curr_time AND `seen` = 1");
} else {
$query = prepare("DELETE FROM ``bans`` WHERE `expires` IS NOT NULL AND `expires` < :curr_time");
$query = prepare("DELETE FROM ``bans`` WHERE `expires` IS NOT NULL AND `expires` + :moratorium < :curr_time");
}
$query->bindValue(':moratorium', $moratorium);
$query->bindValue(':curr_time', time());
$query->execute() or error(db_error($query));

View File

@ -1569,8 +1569,7 @@
// Enable the moving of single replies
$config['move_replies'] = false;
// How often (minimum) to purge the ban list of expired bans (which have been seen). Only works when
// $config['cache'] is enabled and working.
// How often (minimum) to purge the ban list of expired bans (which have been seen).
$config['purge_bans'] = 60 * 60 * 12; // 12 hours
// Do DNS lookups on IP addresses to get their hostname for the moderator IP pages (?/IP/x.x.x.x).

View File

@ -908,12 +908,12 @@ function checkBan($board = false) {
if ($config['cache']['enabled']) {
$last_time_purged = cache::get('purged_bans_last');
if ($last_time_purged !== false && time() - $last_time_purged > $config['purge_bans']) {
Bans::purge($config['require_ban_view']);
Bans::purge($config['require_ban_view'], $config['purge_bans']);
cache::set('purged_bans_last', time());
}
} else {
// Purge every time.
Bans::purge($config['require_ban_view']);
Bans::purge($config['require_ban_view'], $config['purge_bans']);
}
}
}

View File

@ -7,7 +7,7 @@ require dirname(__FILE__) . '/inc/cli.php';
echo "Clearing expired bans...";
$start = microtime(true);
$deleted_count = Bans::purge($config['require_ban_view']);
$deleted_count = Bans::purge($config['require_ban_view'], $config['purge_bans']);
$delta = microtime(true) - $start;
echo "Deleted $deleted_count expired bans in $delta seconds!";
modLog("Deleted expired bans in {$delta}s with tools/maintenance.php");