diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog
index 89eb5d2ba9..d5ff1e36e6 100644
--- a/pandora_console/ChangeLog
+++ b/pandora_console/ChangeLog
@@ -1,3 +1,10 @@
+2012-06-08 Dario Rodriguez <dario.rodriguez@artica.es>
+
+	* operation/tree.php: Improved performance of tree
+	view for policies.
+
+	MERGED FROM 4.0.2
+
 2012-06-08  Ramon Novoa  <rnovoa@artica.es>
 
 	* include/db/postgresql.php,
diff --git a/pandora_console/operation/tree.php b/pandora_console/operation/tree.php
index c5f8377a7e..debd72c8eb 100644
--- a/pandora_console/operation/tree.php
+++ b/pandora_console/operation/tree.php
@@ -824,34 +824,10 @@ function printTree_($type) {
 				case 'policies':
 					$id = $item['id'];
 					$name = $item['name'];
-					$agentes = db_get_all_rows_sql("SELECT id_agente FROM tagente
-													WHERE id_agente IN (SELECT id_agent FROM tpolicy_agents
-																		WHERE id_policy=$id)");
-					if ($agentes === false) {
-						$agentes = array();
-					}
-					$num_ok = 0;
-					$num_critical = 0;
-					$num_warning = 0;
-					$num_unknown = 0;
-					foreach ($agentes as $agente) {
-						$stat = reporting_get_agent_module_info ($agente["id_agente"]);
-
-						switch ($stat['status']) {
-							case 'agent_ok.png':
-								$num_ok++;
-								break;
-							case 'agent_critical.png':
-								$num_critical++;
-								break;
-							case 'agent_warning.png':
-								$num_warning++;
-								break;
-							case 'agent_down.png':
-								$num_unknown++;
-								break;
-						}
-					}
+					$num_ok = policies_agents_ok($id);
+					$num_critical = policies_agents_critical($id);
+					$num_warning = policies_agents_warning($id);
+					$num_unknown = policies_agents_unknown($id);
 					break;
 				case 'module':
 					$id = str_replace(array(' ','#'), array('_articapandora_'.ord(' ').'_pandoraartica_', '_articapandora_'.ord('#').'_pandoraartica_'),io_safe_output($item['nombre']));