Ease toggling between optimization and legacy algorithms

This commit is contained in:
Romain Quetiez
2025-07-11 15:24:14 +02:00
parent 726542dd66
commit bbf7a8cc42

View File

@@ -203,8 +203,7 @@ class RelationEdge extends GraphEdge
*/
class RelationGraph extends SimpleGraph
{
private const OPTIMIZED_QUICK_AND_DIRTY = true; // For testing purposes only, to be removed later
private static bool $bOptimizationEnabled = true;
protected $aSourceNodes; // Index of source nodes (for a quicker access)
protected $aSinkNodes; // Index of sink nodes (for a quicker access)
protected $aRedundancySettings; // Cache of user settings
@@ -219,6 +218,16 @@ class RelationGraph extends SimpleGraph
$this->aContextSearches = array();
}
static public function GetOptimizationEnabled(): bool
{
return static::$bOptimizationEnabled;
}
static public function SetOptimizationEnabled(bool $bEnabled)
{
static::$bOptimizationEnabled = $bEnabled;
}
/**
* Add an object that will be the starting point for building the relations downstream
*
@@ -264,7 +273,7 @@ class RelationGraph extends SimpleGraph
throw new Exception("Invalid context query '$sOQL'. A context query must contain at least two columns. Columns: ".implode(', ', $aAliases).'. ');
}
if (self::OPTIMIZED_QUICK_AND_DIRTY) {
if (static::GetOptimizationEnabled()) {
$sClass = $oSearch->GetClass();
$this->aContextSearches[$sClass][] = array('key' => $key, 'search' => $oSearch);
}
@@ -437,7 +446,7 @@ class RelationGraph extends SimpleGraph
*/
protected function AddRelatedObjects($sRelCode, $bDown, $oObjectNode, $iMaxDepth, $bEnableRedundancy)
{
if (self::OPTIMIZED_QUICK_AND_DIRTY) {
if (static::GetOptimizationEnabled()) {
$this->AddRelatedObjects_Optimized();
return;
}
@@ -829,7 +838,7 @@ class RelationGraph extends SimpleGraph
*/
private function MarkContextNodesAsReached()
{
if (self::OPTIMIZED_QUICK_AND_DIRTY) {
if (static::GetOptimizationEnabled()) {
$this->MarkContextNodesAsReached_Optimized();
return;
}