From b2cf9fc6a587c8d2838a3a6902cf8df6afc333c6 Mon Sep 17 00:00:00 2001 From: ghost Date: Tue, 13 Jun 2023 16:51:16 +0300 Subject: [PATCH] do table optimization in separated transaction --- crontab/cleaner.php | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/crontab/cleaner.php b/crontab/cleaner.php index 7a3e881..53ef8f8 100644 --- a/crontab/cleaner.php +++ b/crontab/cleaner.php @@ -41,10 +41,10 @@ $logsCleanerDeleted = 0; $logsCrawlerDeleted = 0; // Begin update -$db->beginTransaction(); - try { + $db->beginTransaction(); + // Get cleaner queue foreach ($db->getCleanerQueue(CLEAN_HOST_LIMIT, time() - CLEAN_HOST_SECONDS_OFFSET) as $host) { @@ -227,17 +227,30 @@ try { // Commit results $db->commit(); - // Optimize tables - if (CLEAN_DB_TABLES_OPTIMIZATION) { +} catch (Exception $e) { + + $db->rollBack(); + + var_dump($e); +} + +// Optimize tables +if (CLEAN_DB_TABLES_OPTIMIZATION) { + + try { + + $db->beginTransaction(); $db->optimize(); - } -} catch(Exception $e) { + $db->commit(); - var_dump($e); + } catch (Exception $e) { - $db->rollBack(); + $db->rollBack(); + + var_dump($e); + } } // Debug