From df216c95ecafa49f690d71835b5da1ff3f372564 Mon Sep 17 00:00:00 2001 From: Sebastian Mendel Date: Fri, 9 May 2008 13:38:03 +0000 Subject: [PATCH] cache table information --- libraries/Table.class.php | 25 ++++++++++++++++--------- libraries/database_interface.lib.php | 9 ++++++++- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/libraries/Table.class.php b/libraries/Table.class.php index 9ef9ba8af..b811cfedf 100644 --- a/libraries/Table.class.php +++ b/libraries/Table.class.php @@ -8,8 +8,11 @@ /** * @todo make use of PMA_Message and PMA_Error */ -class PMA_Table { +class PMA_Table +{ + static $cache = array(); + /** * @var string table name */ @@ -240,7 +243,10 @@ class PMA_Table { // from the result set are NULL except Name and Comment. // MySQL from 5.0.0 to 5.0.12 returns 'view', // from 5.0.13 returns 'VIEW'. - $comment = strtoupper(PMA_DBI_fetch_value('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . $table . '\'', 0, 'Comment')); + if (! isset(PMA_Table::$cache[$db][$table]['Comment'])) { + PMA_Table::$cache[$db][$table] = PMA_DBI_fetch_single_row('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . $table . '\''); + } + $comment = strtoupper(PMA_Table::$cache[$db][$table]['Comment']); // use substr() because the comment might contain something like: // (VIEW 'BASE2.VTEST' REFERENCES INVALID TABLE(S) OR COLUMN(S) OR FUNCTION) return (substr($comment, 0, 4) == 'VIEW'); @@ -380,17 +386,17 @@ class PMA_Table { { $row_count = false; - if (! $force_exact) { - $row_count = PMA_DBI_fetch_value( - 'SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' - . PMA_sqlAddslashes($table, true) . '\';', - 0, 'Rows'); - } - if (null === $is_view) { $is_view = PMA_Table::isView($db, $table); } + if (! $force_exact) { + if (! isset(PMA_Table::$cache[$db][$table]['Rows']) && ! $is_view) { + PMA_Table::$cache[$db][$table] = PMA_DBI_fetch_single_row('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . PMA_sqlAddslashes($table, true) . '\''); + } + $row_count = PMA_Table::$cache[$db][$table]['Rows']; + } + // for a VIEW, $row_count is always false at this point if (false === $row_count || $row_count < $GLOBALS['cfg']['MaxExactCount']) { if (! $is_view) { @@ -421,6 +427,7 @@ class PMA_Table { } } } + PMA_Table::$cache[$db][$table]['Rows'] = $row_count; } if ($ret) { diff --git a/libraries/database_interface.lib.php b/libraries/database_interface.lib.php index 29a27db8c..f5b1002b5 100644 --- a/libraries/database_interface.lib.php +++ b/libraries/database_interface.lib.php @@ -201,6 +201,7 @@ function PMA_DBI_get_tables($database, $link = null) * PMA_DBI_get_tables_full('my_database', 'my_tables_', 'comment')); * * + * @todo move into PMA_Table * @uses PMA_DBI_fetch_result() * @uses PMA_escape_mysql_wildcards() * @uses PMA_backquote() @@ -219,6 +220,8 @@ function PMA_DBI_get_tables($database, $link = null) function PMA_DBI_get_tables_full($database, $table = false, $tbl_is_group = false, $link = null, $limit_offset = 0, $limit_count = false) { + require_once './libraries/Table.class.php'; + if (true === $limit_count) { $limit_count = $GLOBALS['cfg']['MaxTableList']; } @@ -301,7 +304,7 @@ function PMA_DBI_get_tables_full($database, $table = false, .' LIKE \'' . PMA_escape_mysql_wildcards(addslashes($table)) . '%\''; } else { $sql = 'SHOW TABLE STATUS FROM ' - . PMA_backquote($each_database) . ';'; + . PMA_backquote($each_database); } $each_tables = PMA_DBI_fetch_result($sql, 'Name', null, $link); @@ -372,6 +375,10 @@ function PMA_DBI_get_tables_full($database, $table = false, uksort($tables[$key], 'strnatcasecmp'); } } + + // cache table data + // so PMA_Table does not require to issue SHOW TABLE STATUS again + PMA_Table::$cache = $tables; if (! is_array($database)) { if (isset($tables[$database])) {