[Piwik-svn] r505 - in trunk/modules: . Archive DataTable

svnmaster at piwik.org svnmaster at piwik.org
Sun Jun 1 23:05:50 CEST 2008


Author: matt
Date: 2008-06-01 23:05:48 +0200 (Sun, 01 Jun 2008)
New Revision: 505

Modified:
   trunk/modules/Archive/Array.php
   trunk/modules/DataTable.php
   trunk/modules/DataTable/Manager.php
   trunk/modules/DataTable/Row.php
Log:
- recursion optimization: we first truncate the root table, then the child tables
- changed so that getId() on DataTable are indexed at 0. Im not sure this is backward compatible

Modified: trunk/modules/Archive/Array.php
===================================================================
--- trunk/modules/Archive/Array.php	2008-06-01 20:19:28 UTC (rev 504)
+++ trunk/modules/Archive/Array.php	2008-06-01 21:05:48 UTC (rev 505)
@@ -154,17 +154,6 @@
 	 */
 	public function getDataTableFromNumeric( $fields )
 	{
-		// Simple algorithm not efficient that does the same as the following code
-		/*
-		$table = new Piwik_DataTable_Array;
-		foreach($this->archives as $archive)
-		{
-			$subTable =  $archive->getDataTableFromNumeric( $fields ) ;
-			$table->addTable($subTable, $archive->getPrettyDate());
-		}
-		return $table;
-		*/
-
 		if(!is_array($fields))
 		{
 			$fields = array($fields);
@@ -172,7 +161,6 @@
 		
 		$inName = "'" . implode("', '",$fields) . "'";
 		
-		
 		// we select in different shots
 		// one per distinct table (case we select last 300 days, maybe we will  select from 10 different tables)
 		$queries = array();
@@ -188,8 +176,6 @@
 			// for every query store IDs
 			$queries[$table][] = $archive->getIdArchive();
 		}
-//		var_dump($queries);
-
 		// we select the requested value
 		$db = Zend_Registry::get('db');
 		
@@ -237,8 +223,6 @@
 			
 			$this->loadMetaData($tableArray, $this->archives[$timestamp]);
 		}
-		
-//		echo $tableArray;exit;
 		return $tableArray;
 	}
 

Modified: trunk/modules/DataTable/Manager.php
===================================================================
--- trunk/modules/DataTable/Manager.php	2008-06-01 20:19:28 UTC (rev 504)
+++ trunk/modules/DataTable/Manager.php	2008-06-01 21:05:48 UTC (rev 505)
@@ -52,7 +52,7 @@
 	public function addTable( $table )
 	{
 		$this->tables[] = $table;
-		return count($this->tables);
+		return count($this->tables) - 1;
 	}
 	
 	/**
@@ -65,29 +65,14 @@
 	 */
 	public function getTable( $idTable )
 	{
-		// the array tables is indexed at 0 
-		// but the index is computed as the count() of the array after inserting the table
-		$idTable -= 1;
-		
 		if(!isset($this->tables[$idTable]))
 		{
-			throw new Exception("The requested table id=$idTable couldn't be found in the DataTable Manager");
+			throw new Exception(sprintf("The requested table (id = %d) couldn't be found in the DataTable Manager", $idTable));
 		}
-		
 		return $this->tables[$idTable];
 	}
 	
 	/**
-	 * Returns all the dataTable registered in the manager
-	 * 
-	 * @return array of Piwik_DataTable
-	 */
-	public function getTables()
-	{
-		return $this->tables;
-	}
-	
-	/**
 	 * Delete all the registered DataTables from the manager
 	 * 
 	 * @return void
@@ -97,6 +82,15 @@
 		$this->tables = array();
 	}
 	
+	public function deleteTable( $id )
+	{
+//		echo "d $id ; ";
+		if(isset($this->tables[$id]))
+		{
+			$this->tables[$id] = null;
+		}
+	}
+	
 	/**
 	 * Returns the number of DataTable currently registered.
 	 * 

Modified: trunk/modules/DataTable/Row.php
===================================================================
--- trunk/modules/DataTable/Row.php	2008-06-01 20:19:28 UTC (rev 504)
+++ trunk/modules/DataTable/Row.php	2008-06-01 21:05:48 UTC (rev 505)
@@ -91,7 +91,8 @@
 		$idSubtable = $this->c[self::DATATABLE_ASSOCIATED];
 		if($idSubtable !== null)
 		{
-			unset($idSubtable);
+			Piwik_DataTable_Manager::getInstance()->deleteTable($idSubtable);
+			$idSubtable = null;
 		}
 	}
 

Modified: trunk/modules/DataTable.php
===================================================================
--- trunk/modules/DataTable.php	2008-06-01 20:19:28 UTC (rev 504)
+++ trunk/modules/DataTable.php	2008-06-01 21:05:48 UTC (rev 505)
@@ -743,6 +743,11 @@
 			throw new Exception("Maximum recursion level of ".self::MAXIMUM_DEPTH_LEVEL_ALLOWED. " reached. You have probably set a DataTable_Row with an associated DataTable which belongs already to its parent hierarchy.");
 		}
 		
+		if( !is_null($maximumRowsInDataTable) )
+		{
+			$filter = new Piwik_DataTable_Filter_AddSummaryRow($this, $maximumRowsInDataTable - 1);
+		}
+		
 		// For each row, get the serialized row
 		// If it is associated to a sub table, get the serialized table recursively ;
 		// but returns all serialized tables and subtable in an array of 1 dimension!
@@ -766,11 +771,6 @@
 			$forcedId = 0;
 		}
 		
-		if( !is_null($maximumRowsInDataTable) )
-		{
-			$filter = new Piwik_DataTable_Filter_AddSummaryRow($this, $maximumRowsInDataTable - 1);
-		}
-		
 		// we then serialize the rows and store them in the serialized dataTable
 		$aSerializedDataTable[$forcedId] = serialize($this->rows + array( self::ID_SUMMARY_ROW => $this->summaryRow));
 		
@@ -997,6 +997,9 @@
 	 */
 	public function __destruct()
 	{
+//		static $c = 0;
+//		$c++;
+//		echo " k ".$this->getId();
 		unset($this->rows);
 	}
 	



More information about the Piwik-svn mailing list