From bbf7a8cc42517b0f70a70fdfa02e7b8b45d3fb67 Mon Sep 17 00:00:00 2001 From: Romain Quetiez Date: Fri, 11 Jul 2025 15:24:14 +0200 Subject: [PATCH] Ease toggling between optimization and legacy algorithms --- core/relationgraph.class.inc.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/core/relationgraph.class.inc.php b/core/relationgraph.class.inc.php index a45285ce3..f289ad92c 100644 --- a/core/relationgraph.class.inc.php +++ b/core/relationgraph.class.inc.php @@ -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; }