瀏覽代碼

Fix warning.
Reduce memory need for getmin/max on large graphs.

Laurent Destailleur 3 年之前
父節點
當前提交
16ee47b12c
共有 3 個文件被更改,包括 26 次插入24 次删除
  1. 1 1
      htdocs/core/boxes/box_scheduled_jobs.php
  2. 24 22
      htdocs/core/class/dolgraph.class.php
  3. 1 1
      htdocs/main.inc.php

+ 1 - 1
htdocs/core/boxes/box_scheduled_jobs.php

@@ -85,7 +85,7 @@ class box_scheduled_jobs extends ModeleBoxes
 			$resultarray = array();
 
 			$result = 0;
-			$sql = "SELECT t.rowid, t.datelastrun, t.datenextrun,";
+			$sql = "SELECT t.rowid, t.datelastrun, t.datenextrun, t.datestart,";
 			$sql .= " t.label, t.status, t.test, t.lastresult";
 			$sql .= " FROM " . MAIN_DB_PREFIX . "cronjob as t";
 			$sql .= " WHERE status <> ".$cronstatic::STATUS_DISABLED;

+ 24 - 22
htdocs/core/class/dolgraph.class.php

@@ -596,7 +596,7 @@ class DolGraph
 
 	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
 	/**
-	 * Get max value
+	 * Get max value among all values of all series
 	 *
 	 * @return	int		Max value
 	 */
@@ -607,25 +607,26 @@ class DolGraph
 			return 0;
 		}
 
-		$k = 0;
-		$vals = array();
+		$max = null;
 
-		$nblines = count($this->data);
-		$nbvalues = (empty($this->data[0]) ? 0 : count($this->data[0]) - 1);
+		$nbseries = (empty($this->data[0]) ? 0 : count($this->data[0]) - 1);
 
-		for ($j = 0; $j < $nblines; $j++) {
-			for ($i = 0; $i < $nbvalues; $i++) {
-				$vals[$k] = $this->data[$j][$i + 1];
-				$k++;
+		foreach($this->data as $x) {	// Loop on each x
+			for ($i = 0; $i < $nbseries; $i++) {	// Loop on each serie
+				if (is_null($max)) {
+					$max = $x[$i + 1];		// $i+1 because the index 0 is the legend
+				} elseif ($max < $x[$i + 1]) {
+					$max = $x[$i + 1];
+				}
 			}
 		}
-		rsort($vals);
-		return $vals[0];
+
+		return $max;
 	}
 
 	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
 	/**
-	 * Return min value of all data
+	 * Return min value of all values of all series
 	 *
 	 * @return	int		Min value of all data
 	 */
@@ -636,20 +637,21 @@ class DolGraph
 			return 0;
 		}
 
-		$k = 0;
-		$vals = array();
+		$min = null;
 
-		$nblines = count($this->data);
-		$nbvalues = (empty($this->data[0]) ? 0 : count($this->data[0]) - 1);
+		$nbseries = (empty($this->data[0]) ? 0 : count($this->data[0]) - 1);
 
-		for ($j = 0; $j < $nblines; $j++) {
-			for ($i = 0; $i < $nbvalues; $i++) {
-				$vals[$k] = $this->data[$j][$i + 1];
-				$k++;
+		foreach($this->data as $x) {	// Loop on each x
+			for ($i = 0; $i < $nbseries; $i++) {	// Loop on each serie
+				if (is_null($min)) {
+					$min = $x[$i + 1];		// $i+1 because the index 0 is the legend
+				} elseif ($min > $x[$i + 1]) {
+					$min = $x[$i + 1];
+				}
 			}
 		}
-		sort($vals);
-		return $vals[0];
+
+		return $min;
 	}
 
 	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps

+ 1 - 1
htdocs/main.inc.php

@@ -1854,7 +1854,7 @@ function top_menu($head, $title = '', $target = '', $disablejs = 0, $disablehead
 		if (empty($conf->global->MAIN_PRINT_DISABLELINK) && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $conf->browser->layout != 'phone') {
 			$qs = dol_escape_htmltag($_SERVER["QUERY_STRING"]);
 
-			if (is_array($_POST)) {
+			if (isset($_POST) && is_array($_POST)) {
 				foreach ($_POST as $key => $value) {
 					if ($key !== 'action' && $key !== 'password' && !is_array($value)) {
 						$qs .= '&'.$key.'='.urlencode($value);