anti-bot.php: use transactions

This commit is contained in:
Zankaria 2024-11-28 16:01:24 +01:00
parent 73bc23a4c7
commit b459551ccb

View file

@ -190,18 +190,21 @@ class AntiBot {
} }
} }
function _create_antibot($board, $thread) { function _create_antibot($pdo, $board, $thread) {
global $config, $purged_old_antispam; global $config, $purged_old_antispam;
$antibot = new AntiBot(array($board, $thread)); $antibot = new AntiBot(array($board, $thread));
try {
$pdo->beginTransaction();
// Delete old expired antispam, skipping those with NULL expiration timestamps (infinite lifetime). // Delete old expired antispam, skipping those with NULL expiration timestamps (infinite lifetime).
if (!isset($purged_old_antispam) && $config['auto_maintenance']) { if (!isset($purged_old_antispam) && $config['auto_maintenance']) {
$purged_old_antispam = true; $purged_old_antispam = true;
purge_old_antispam(); purge_old_antispam();
} }
retry_on_deadlock(4, function() use($thread, $board, $config) { retry_on_deadlock(4, function() use($config, $board, $thread) {
// Keep the now invalid timestamps around for a bit to enable users to post if they're still on an old version of // Keep the now invalid timestamps around for a bit to enable users to post if they're still on an old version of
// the HTML page. // the HTML page.
// By virtue of existing, we know that we're making a new version of the page, and the user from now on may just reload. // By virtue of existing, we know that we're making a new version of the page, and the user from now on may just reload.
@ -239,6 +242,11 @@ function _create_antibot($board, $thread) {
error_log('Multiple deadlocks on _create_antibot while inserting, skipping'); error_log('Multiple deadlocks on _create_antibot while inserting, skipping');
} }
} }
} catch (\PDOException $e) {
$pdo->rollBack();
throw $e;
}
$pdo->commit();
return $antibot; return $antibot;
} }