From: Davide Franco Date: Sun, 26 Jun 2011 16:16:51 +0000 (+0200) Subject: bacula-web: Optimized php code in bweb classe X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=d371c6919b6cd1a10dc79a351d4012b035b72847;p=bacula%2Fbacula bacula-web: Optimized php code in bweb classe - Optimized Get_Pools_List() function in BWeb class - Added defautl fetch mode to DB class - Optimized code in CountVolumesByPool() function --- diff --git a/gui/bacula-web/includes/bweb.inc.php b/gui/bacula-web/includes/bweb.inc.php index 08e221d201..04e1a6221e 100644 --- a/gui/bacula-web/includes/bweb.inc.php +++ b/gui/bacula-web/includes/bweb.inc.php @@ -52,6 +52,7 @@ class Bweb extends DB }else { $this->driver = $dsn['phptype']; register_shutdown_function(array(&$this,'close') ); + $this->db_link->setFetchMode(DB_FETCHMODE_ASSOC); } // Initialize smarty template classe @@ -317,20 +318,14 @@ class Bweb extends DB // Return the list of Pools in a array public function Get_Pools_List() { - $pool_list = array(); - $result = ""; - - $query = "SELECT Name, PoolId FROM Pool"; - - $result = $this->db_link->query ( $query ); + $result = ""; + $query = "SELECT Name, PoolId FROM Pool"; + $result = $this->db_link->query ( $query ); if( PEAR::isError( $result ) ) { - die( "Unable to get the pool list from catalog" ); + $this->TriggerDBError( "Unable to get the pool list from catalog", $result ); }else { - while( $pool = $result->fetchRow(DB_FETCHMODE_ASSOC) ) { - array_push( $pool_list, array( $pool['name'] => $pool['poolid'] ) ); - } - return $pool_list; + return $result; } } @@ -424,18 +419,18 @@ class Bweb extends DB public function CountVolumesByPool( $pool_id ) { - foreach( $pool_id as $pool_name => $pool ) { - $query = "SELECT COUNT(*) AS nb_vol FROM Media WHERE PoolId = '$pool_id'"; - $result = $this->db_link->query( $query ); - - if( PEAR::isError( $result ) ) { - $this->TriggerDBError( 'Unable to get volume number from catalog', $result ); - //die("Unable to get volume number from catalog"); - }else{ - $nb_vol = $result->fetchRow(DB_FETCHMODE_ASSOC); - return array( $pool_name, $nb_vol['nb_vol'] ); - } - } + var_dump( $pool_id ); + $res = null; + $nb_vol = null; + $query = "SELECT COUNT(*) as nb_vol FROM media WHERE poolid = $pool_id"; + + $res = $this->db_link->query( $query ); + if( PEAR::isError( $res ) ) + $this->triggerDBError( 'Unable to get volume number from pool', $res ); + else + $nb_vol = $res->fetchRow( ); + + return array( $pool_name, $nb_vol['nb_vol'] ); } public function GetStoredFiles( $delay = LAST_DAY ) diff --git a/gui/bacula-web/index.php b/gui/bacula-web/index.php index 2672381fb1..e665c449c0 100644 --- a/gui/bacula-web/index.php +++ b/gui/bacula-web/index.php @@ -87,10 +87,8 @@ $data = array(); $graph = new BGraph( "graph1.png" ); $pools = $dbSql->Get_Pools_List(); - -foreach( $pools as $pool ) { - array_push( $data, $dbSql->CountVolumesByPool( $pool ) ); -} +while( $pool = $pools->fetchRow( ) ) + array_push( $data, $pool ); $graph->SetData( $data, 'pie', 'text-data-single' ); $graph->SetGraphSize( 400, 230 );