summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Foster <savetheinternet@tinyboard.org>2013-08-04 04:48:13 -0400
committerMichael Foster <savetheinternet@tinyboard.org>2013-08-04 04:48:13 -0400
commit0890557ebb666dacf3356aae262ec79f486fa25d (patch)
tree96df8f61d5339418032535bd44a2de14e6c4073d
parentfb3b9ea868b7c65e18f8cde5d4d66388d78e5da8 (diff)
Don't purge the ban list of expires bans every time somebody posts. Add a timer option. Less SQL queries when posting.
-rw-r--r--inc/config.php4
-rw-r--r--inc/functions.php10
2 files changed, 14 insertions, 0 deletions
diff --git a/inc/config.php b/inc/config.php
index 06c6c243..bc7711e6 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -983,6 +983,10 @@
// persistent spammers and ban evaders. Again, a little more database load.
$config['ban_cidr'] = true;
+ // How often (minimum) to purge the ban list of expired bans (which have been seen). Only works when
+ // $config['cache'] is enabled and working.
+ $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).
$config['mod']['dns_lookup'] = true;
// How many recent posts, per board, to show in ?/IP/x.x.x.x.
diff --git a/inc/functions.php b/inc/functions.php
index 8b2c4c7b..0c9b9983 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -687,9 +687,19 @@ function checkBan($board = 0) {
// No reason to keep expired bans in the database (except those that haven't been viewed yet)
function purge_bans() {
+ global $config;
+
+ if ($config['cache']['enabled'] && $last_time_purged = cache::get('purged_bans_last')) {
+ if (time() - $last_time_purged < 60 * 30)
+ return;
+ }
+
$query = prepare("DELETE FROM ``bans`` WHERE `expires` IS NOT NULL AND `expires` < :time AND `seen` = 1");
$query->bindValue(':time', time());
$query->execute() or error(db_error($query));
+
+ if ($config['cache']['enabled'])
+ cache::set('purged_bans_last', time());
}
function threadLocked($id) {