From 0f890ad228a3a705b47650a95b096caded4b51f7 Mon Sep 17 00:00:00 2001 From: Eric Date: Fri, 6 Sep 2019 10:33:21 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B02272=20-=20OQL=20performance=20(Expressi?= =?UTF-8?q?on=20cache=20is=20configurable)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/config.class.inc.php | 20 ++++++++++++++------ core/expressioncache.class.inc.php | 17 +++++++++++++---- test/core/OQLToSQLTest.php | 4 ++++ 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/core/config.class.inc.php b/core/config.class.inc.php index a24741529..30e7dc2f5 100644 --- a/core/config.class.inc.php +++ b/core/config.class.inc.php @@ -1184,6 +1184,14 @@ class Config 'source_of_value' => '', 'show_in_conf_sample' => false, ), + 'expression_cache_enabled' => array( + 'type' => 'bool', + 'description' => 'If set, DBSearch will use cache for query expression generation', + 'default' => true, + 'value' => true, + 'source_of_value' => '', + 'show_in_conf_sample' => false, + ), 'log_kpi_record_oql' => array( 'type' => 'integer', 'description' => '1 => Record OQL requests and parameters', @@ -1451,6 +1459,12 @@ class Config $sNoise = trim(ob_get_contents()); ob_end_clean(); } + catch(Error $e) + { + // PHP 7 + throw new ConfigException('Error in configuration file', + array('file' => $sConfigFile, 'error' => $e->getMessage().' at line '.$e->getLine())); + } catch (Exception $e) { // well, never reach in case of parsing error :-( @@ -1458,12 +1472,6 @@ class Config throw new ConfigException('Error in configuration file', array('file' => $sConfigFile, 'error' => $e->getMessage())); } - catch(Error $e) - { - // PHP 7 - throw new ConfigException('Error in configuration file', - array('file' => $sConfigFile, 'error' => $e->getMessage().' at line '.$e->getLine())); - } if (strlen($sNoise) > 0) { // Note: sNoise is an html output, but so far it was ok for me (e.g. showing the entire call stack) diff --git a/core/expressioncache.class.inc.php b/core/expressioncache.class.inc.php index 44eef4323..e81a61bd3 100644 --- a/core/expressioncache.class.inc.php +++ b/core/expressioncache.class.inc.php @@ -29,8 +29,13 @@ class ExpressionCache * * @return mixed|null */ - static public function GetCachedExpression($sClass, $sAttCode) + public static function GetCachedExpression($sClass, $sAttCode) { + if (!utils::GetConfig()->Get('expression_cache_enabled')) + { + return null; + } + // read current cache @include_once (static::GetCacheFileName()); @@ -54,8 +59,12 @@ class ExpressionCache * @throws \CoreException * @throws \DictExceptionUnknownLanguage */ - static public function Warmup() + public static function Warmup() { + if (!utils::GetConfig()->Get('expression_cache_enabled')) + { + return; + } // Store current language $sUserLang = Dict::GetUserLanguage(); $aLanguages = Dict::GetLanguages(); @@ -105,7 +114,7 @@ EOF; * @return string * @throws \CoreException */ - static private function GetSerializedExpression($sClass, $sAttCode) + private static function GetSerializedExpression($sClass, $sAttCode) { $sKey = static::GetKey($sClass, $sAttCode); $oExpr = DBObjectSearch::GetPolymorphicExpression($sClass, $sAttCode); @@ -118,7 +127,7 @@ EOF; * * @return string */ - static private function GetKey($sClass, $sAttCode) + private static function GetKey($sClass, $sAttCode) { return $sClass.'::'.$sAttCode; } diff --git a/test/core/OQLToSQLTest.php b/test/core/OQLToSQLTest.php index ee4edebd4..bfd192e8a 100644 --- a/test/core/OQLToSQLTest.php +++ b/test/core/OQLToSQLTest.php @@ -59,6 +59,7 @@ class OQLToSQLTest extends ItopDataTestCase { utils::GetConfig()->Set('use_legacy_dbsearch', true, 'Test'); utils::GetConfig()->Set('apc_cache.enabled', false, 'Test'); + utils::GetConfig()->Set('expression_cache_enabled', false, 'Test'); utils::GetConfig()->Set('query_cache_enabled', false, 'Test'); $sConfigFile = utils::GetConfig()->GetLoadedFile(); @chmod($sConfigFile, 0770); @@ -89,6 +90,7 @@ class OQLToSQLTest extends ItopDataTestCase $this->assertTrue(utils::GetConfig()->Get('use_legacy_dbsearch')); $this->assertFalse(utils::GetConfig()->Get('apc_cache.enabled')); $this->assertFalse(utils::GetConfig()->Get('query_cache_enabled')); + $this->assertFalse(utils::GetConfig()->Get('expression_cache_enabled')); $aPrevious = $this->GetPreviousTestResult($this->GetId()); if (is_null($aPrevious)) @@ -106,6 +108,7 @@ class OQLToSQLTest extends ItopDataTestCase utils::GetConfig()->Set('use_legacy_dbsearch', false, 'test'); utils::GetConfig()->Set('apc_cache.enabled', false, 'test'); utils::GetConfig()->Set('query_cache_enabled', false, 'test'); + utils::GetConfig()->Set('expression_cache_enabled', false, 'test'); $sConfigFile = utils::GetConfig()->GetLoadedFile(); @chmod($sConfigFile, 0770); utils::GetConfig()->WriteToFile(); @@ -136,6 +139,7 @@ class OQLToSQLTest extends ItopDataTestCase $this->assertFalse(utils::GetConfig()->Get('use_legacy_dbsearch')); $this->assertFalse(utils::GetConfig()->Get('apc_cache.enabled')); $this->assertFalse(utils::GetConfig()->Get('query_cache_enabled')); + $this->assertFalse(utils::GetConfig()->Get('expression_cache_enabled')); $aResult = $this->OQLRunner($sOQL, $aOrderBy, $aArgs, $aAttToLoad, $aExtendedDataSpec, $iLimitCount, $iLimitStart); $this->assertNull($aResult);