From 30d9af4789fafdf766ea2c3eb0eafa0b4bfea312 Mon Sep 17 00:00:00 2001 From: Martyn Dale Date: Thu, 21 Nov 2013 13:00:43 -0500 Subject: [PATCH] Fix performance issue with many databases (when only_db is defined) --- libraries/navigation/Nodes/Node.class.php | 29 ++++++++++++++++++----- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/libraries/navigation/Nodes/Node.class.php b/libraries/navigation/Nodes/Node.class.php index a0f349773e..dad71bf8a8 100644 --- a/libraries/navigation/Nodes/Node.class.php +++ b/libraries/navigation/Nodes/Node.class.php @@ -359,12 +359,29 @@ class Node */ public function getData($type, $pos, $searchClause = '') { - $query = "SELECT `SCHEMA_NAME` "; - $query .= "FROM `INFORMATION_SCHEMA`.`SCHEMATA` "; - $query .= $this->_getWhereClause($searchClause); - $query .= "ORDER BY `SCHEMA_NAME` ASC "; - $query .= "LIMIT $pos, {$GLOBALS['cfg']['MaxNavigationItems']}"; - return $GLOBALS['dbi']->fetchResult($query); + if ($type == 'databases' + && ! empty($GLOBALS['cfg']['Server']['only_db']) + ) { + $db_list = $GLOBALS['cfg']['Server']['only_db']; + $query = "SELECT * FROM ( SELECT '"; + + if (is_string($db_list)) { + $db_list = array($db_list); + } + + if (count($db_list)) { + $query .= implode("' UNION ALL SELECT '", $db_list); + $query .= "' "; + } + return $GLOBALS['dbi']->fetchResult($query . ") as alias"); + } else { + $query = "SELECT `SCHEMA_NAME` "; + $query .= "FROM `INFORMATION_SCHEMA`.`SCHEMATA` "; + $query .= $this->_getWhereClause($searchClause); + $query .= "ORDER BY `SCHEMA_NAME` ASC "; + $query .= "LIMIT $pos, {$GLOBALS['cfg']['MaxNavigationItems']}"; + return $GLOBALS['dbi']->fetchResult($query); + } } /**