From 0030d5c2b8d0448a6c451a179904975f299578e7 Mon Sep 17 00:00:00 2001 From: bruno-ds Date: Mon, 1 Mar 2021 15:30:40 +0100 Subject: [PATCH] =?UTF-8?q?N=C2=B03764=20-=20add=20transactions=5Fgc=5Fthr?= =?UTF-8?q?eshold=20in=20order=20to=20tune=20CSRF=20token=20GC=20load?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/transaction.class.inc.php | 8 ++++++++ core/config.class.inc.php | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/application/transaction.class.inc.php b/application/transaction.class.inc.php index d5388976f..8e3afb2ee 100644 --- a/application/transaction.class.inc.php +++ b/application/transaction.class.inc.php @@ -299,6 +299,14 @@ class privUITransactionFile */ protected static function CleanupOldTransactions($sTransactionDir = null) { + $iThreshold = (int) MetaModel::GetConfig()->Get('transactions_gc_threshold'); + $iThreshold = min(100, $iThreshold); + $iThreshold = max(1, $iThreshold); + if ((100 != $iThreshold) && (rand(1, 100) > $iThreshold)) { + return; + } + + clearstatcache(); $iLimit = time() - 24*3600; $sPattern = $sTransactionDir ? "$sTransactionDir/*" : APPROOT.'data/transactions/*'; $aTransactions = glob($sPattern); diff --git a/core/config.class.inc.php b/core/config.class.inc.php index 0947b20b1..5d6e63938 100644 --- a/core/config.class.inc.php +++ b/core/config.class.inc.php @@ -1065,6 +1065,14 @@ class Config 'source_of_value' => '', 'show_in_conf_sample' => false, ), + 'transactions_gc_threshold' => array( + 'type' => 'integer', + 'description' => 'probability in percent for the garbage collector to be triggered (100 mean always)', + 'default' => 10, // added in itop 2.7.4, before the GC was always called + 'value' => '', + 'source_of_value' => '', + 'show_in_conf_sample' => false, + ), 'log_transactions' => array( 'type' => 'bool', 'description' => 'Whether or not to enable the debug log for the transactions.',