Code

Graphs are now cached
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 24 Aug 2010 13:30:47 +0000 (13:30 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 24 Aug 2010 13:30:47 +0000 (13:30 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19436 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-core/plugins/generic/statistics/class_statistics.inc

index 34c6a7fa88da07df2d656022ad9bcb5b201dd0a9..6be91261bc1e9026bffb4931933ddbc36d31a7b5 100644 (file)
@@ -136,7 +136,6 @@ class statistics extends plugin
         $smarty->assign('graph1DatePicker1', $this->graph1DatePicker1);
         $smarty->assign('graph1DatePicker2', $this->graph1DatePicker2);
 
-        $this->reloadGraphs();
 
         // Do not render anything if we are not prepared to send and receive data via rpc.
         $smarty->assign("rpcConfigured", $this->rpcConfigured);
@@ -175,11 +174,11 @@ class statistics extends plugin
                 msg_dialog::display(_("Error"),msgPool::rpcError($this->rpcHandle->get_error()),ERROR_DIALOG);
             }elseif($res){
                 $this->statisticData = $this->prepareGraphData($res); 
-                $this->reloadGraphs();
             }
             $this->rpcHandle_Error = !$this->rpcHandle->success();
         }
-
+        
+        $this->reloadGraphs();
 
         $smarty->assign('seriesListPerGraph', $this->seriesListPerGraph);
         $smarty->assign('skipSeries', $this->skipSeries);
@@ -401,10 +400,30 @@ class statistics extends plugin
             $seriesCnt ++;
         }
 
+        // Create a dataSet containing all series 
+        $allSeriesDataSet = clone $dataSet;
+        if(!in_array('errorsPerInterval', $this->skipSeries[$gID])){
+            $allSeriesDataSet->AddPoint($gData['errorsPerInterval'], 'Errors');
+            $allSeriesDataSet->SetSerieName(_('Error'), 'Errors');
+            $allSeriesDataSet->AddSerie('Errors');
+        }
+
         // Add timeline
         $dataSet->AddPoint($gData['dates'], 'date');
         $dataSet->SetAbsciseLabelSerie('date');  
 
+        // Read graph from cache?
+        $pCache = new pCache('/var/spool/gosa/');
+        if($pCache->IsInCache($gID,$allSeriesDataSet->GetData())){
+            $filename =  $pCache->GetHash($gID,$allSeriesDataSet->GetData());
+            $filename = '/var/spool/gosa/'.$filename;    
+            if(file_exists($filename) && is_readable($filename)){
+                $this->graphIDs[$gID] = preg_replace("/[^0-9]/","",microtime(TRUE)).rand(0,99999);
+                session::set('statistics::graphFile'.$this->graphIDs[$gID],$filename);
+                return;
+            }
+        }
+
         $chart = new pChart(900,230);  
         $chart->setFixedScale(0.000,$lineMax);
         $chart->setFontProperties("./themes/default/fonts/LiberationSans-Regular.ttf",10);  
@@ -456,6 +475,7 @@ class statistics extends plugin
         $file = '/tmp/graph_'.$this->graphIDs[$gID];
         $chart->Render($file);
         session::set('statistics::graphFile'.$this->graphIDs[$gID],$file);
+        $pCache->WriteToCache($gID,$allSeriesDataSet->GetData(),$chart);   
 
         // Keep a list of all selecteable data-series, to allow the user to disable
         //  or enable series on demand.
@@ -549,6 +569,18 @@ class statistics extends plugin
         $dataSet->AddPoint($keys,"Serie2");  
         $dataSet->SetAbsciseLabelSerie("Serie2");  
 
+        // Read graph from cache?
+        $pCache = new pCache('/var/spool/gosa/');
+        if($pCache->IsInCache($gID,$dataSet->GetData())){
+            $filename =  $pCache->GetHash($gID,$dataSet->GetData());
+            $filename = '/var/spool/gosa/'.$filename;    
+            if(file_exists($filename) && is_readable($filename)){
+                $this->graphIDs[$gID] = preg_replace("/[^0-9]/","",microtime(TRUE)).rand(0,99999);
+                session::set('statistics::graphFile'.$this->graphIDs[$gID],$filename);
+                return;
+            }
+        }
+
         // Set graph area
         $x = 400;
         $y = 200;
@@ -565,6 +597,7 @@ class statistics extends plugin
         $file = '/tmp/graph_'.$this->graphIDs[$gID];
         $chart->Render($file);
         session::set('statistics::graphFile'.$this->graphIDs[$gID],$file);
+        $pCache->WriteToCache($gID,$dataSet->GetData(),$chart);   
     }
 }
 ?>