Explorar o código

BiAuditGenerate :: Implementacja wag względem ilości znalezionych relacji dla danego obiektu

Mariusz Muszyński %!s(int64=8) %!d(string=hai) anos
pai
achega
d5fe964e5f
Modificáronse 1 ficheiros con 16 adicións e 2 borrados
  1. 16 2
      SE/se-lib/Route/UrlAction/BiAuditGenerate.php

+ 16 - 2
SE/se-lib/Route/UrlAction/BiAuditGenerate.php

@@ -2417,7 +2417,17 @@ class BiAuditPowiazania {
 		$this->saveToDb($path);           
 	}
 
-	public function findPowiazania($ID, $progress = 0, $steps = 1, $relation = "") {
+	private static function weightCalc($n) {
+		static $weights = [];
+		if (isset($weights[$n])) {
+			$weight = floor(log(($n - 1) / 10) / log(2)) + 1;
+			if ($weight < 1) $weight = 1;
+			$weights[$n] = $weight;
+		}
+		return $weights[$n];
+	}
+
+	public function findPowiazania($ID, $progress = 0, $steps = 1, $relation = "", $weight = 0) {
 		if (((++$this->step) % 1000000) == 0) {
 			$progressDiff = $progress - $this->lastProgress_slowCheck;
 			if ($progressDiff < 0.00005) {
@@ -2468,8 +2478,12 @@ class BiAuditPowiazania {
 			if (isset($this->path[$node['ID']])) return false;
 			return true;
 		}));
+
 		$count = count($nodes);
-		foreach ($nodes as $i => $node) $this->findPowiazania($node['ID'], ($progress + ($i / ($count * $steps))), ($count * $steps), $node['RELATION_ID']);
+		$weight += self::weightCalc($count);
+		if ($weight <= $this->maxDepth) {
+			foreach ($nodes as $i => $node) $this->findPowiazania($node['ID'], ($progress + ($i / ($count * $steps))), ($count * $steps), $node['RELATION_ID'], $weight);
+		}
 
 		array_pop($this->path);
 	}