Browse Source

FIX: split by 9 labels before aggregation

Giancarlo Voci 7 years ago
parent
commit
3823f44487
2 changed files with 27 additions and 11 deletions
  1. 1 1
      package.json
  2. 26 10
      src/OpenMind/FindBox/FindBoxService.php

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
 	"name": "omlink",
-	"version": "1.12.0",
+	"version": "1.12.1",
 	"codename": "Barricade",
 	"private": true,
 	"description": "OM-Link Engine",

+ 26 - 10
src/OpenMind/FindBox/FindBoxService.php

@@ -37,11 +37,6 @@ class JobManager
 		$this->jobs = [];
 	}
 
-	private function array_diff_symmetric(array $ar1, array $ar2): array
-	{
-		return array_merge(array_diff($ar1, $ar2), array_diff($ar2, $ar1));
-	}
-
 	public function AggregateBlinkByParams()
 	{
 		global $f3;
@@ -85,6 +80,11 @@ class JobManager
 		);
 	}
 
+	private function array_diff_symmetric(array $ar1, array $ar2): array
+	{
+		return array_merge(array_diff($ar1, $ar2), array_diff($ar2, $ar1));
+	}
+
 	public function count()
 	{
 		return count($this->jobs);
@@ -307,6 +307,8 @@ class FindBoxService
 
 			if ($isTimeToAggregateCommands && (count($this->labelToBlink) > 0)) {
 
+				$this->SplitBeforeAggregation();
+
 				foreach($this->labelToBlink as $commandID => &$label) {
 					switch ($label->operation) {
 
@@ -316,7 +318,6 @@ class FindBoxService
 
 							// Rimuove il JOB se esiste
 							$asyncBlinkOFF = new AsyncJobClass($this->findBoxCore, $label->id);
-//							$asyncBlinkOFF->BlinkOFF();
 							$this->jobManager->add($asyncBlinkOFF);
 
 							unset($this->labelToBlink[$commandID]);
@@ -328,7 +329,6 @@ class FindBoxService
 							$this->ServiceLogger->write("BlinkOn for label(s) {$labelJ} requested", 'd/m/Y H:i:s');
 
 							$asyncBlink = new AsyncJobClass($this->findBoxCore, $label->id, $label->params);
-//							$asyncBlink->BlinkON();
 							$this->jobManager->add($asyncBlink);
 
 							unset($this->labelToBlink[$commandID]);
@@ -339,9 +339,6 @@ class FindBoxService
 				$this->ts_ms = NULL;
 			}
 
-//			if ($this->jobManager->count() < 1)
-//				continue;
-
 			$this->jobManager->AggregateBlinkByParams();
 
 			// Async check on JOBS
@@ -500,6 +497,11 @@ class FindBoxService
 		return false;
 	}
 
+	/**
+	 * If a command come with more than 9 label ids, it split command in multiple commands
+	 *
+	 * @param QueueCommand $command
+	 */
 	private function SplitArrayIn9Parts(QueueCommand $command)
 	{
 		// Split blink list by 9 items each array
@@ -511,6 +513,20 @@ class FindBoxService
 		}
 	}
 
+	private function SplitBeforeAggregation()
+	{
+		$newLabelToBlink = [];
+		foreach($this->labelToBlink as $commandID => &$label) {
+			$labelsSplitted = array_chunk($label->id, 9);
+			foreach($labelsSplitted as $labels) {
+				$cmd = clone $label;
+				$cmd->id = $labels;
+				$newLabelToBlink[rand(0, 60000)] = $cmd;
+			}
+		}
+		$this->labelToBlink = $newLabelToBlink;
+	}
+
 	/**
 	 * @param AsyncJobClass $job
 	 * @param array $labels