N°2272 - OQL performance (Expression cache is configurable)

This commit is contained in:
Eric
2019-09-06 10:33:21 +02:00
parent aac6ab0fc6
commit 0f890ad228
3 changed files with 31 additions and 10 deletions

View File

@@ -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)

View File

@@ -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;
}

View File

@@ -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);