use function for caching

This commit is contained in:
Sebastian Mendel
2008-01-22 07:29:08 +00:00
parent 5b7cfdfcf5
commit 801249f3a5
4 changed files with 98 additions and 46 deletions

View File

@@ -51,13 +51,13 @@ $GLOBALS['is_superuser'] = PMA_isSuperuser();
*/ */
function PMA_analyseShowGrant() function PMA_analyseShowGrant()
{ {
if (isset($_SESSION[$GLOBALS['server']]['is_create_db_priv'])) { if (PMA_cacheExists('is_create_db_priv', true)) {
$GLOBALS['is_create_db_priv'] = $_SESSION[$GLOBALS['server']]['is_create_db_priv']; $GLOBALS['is_create_db_priv'] = PMA_cacheGet('is_create_db_priv', true);
$GLOBALS['is_process_priv'] = $_SESSION[$GLOBALS['server']]['is_create_db_priv']; $GLOBALS['is_process_priv'] = PMA_cacheGet('is_process_priv', true);
$GLOBALS['is_reload_priv'] = $_SESSION[$GLOBALS['server']]['is_create_db_priv']; $GLOBALS['is_reload_priv'] = PMA_cacheGet('is_reload_priv', true);
$GLOBALS['db_to_create'] = $_SESSION[$GLOBALS['server']]['is_create_db_priv']; $GLOBALS['db_to_create'] = PMA_cacheGet('db_to_create', true);
$GLOBALS['dbs_where_create_table_allowed'] $GLOBALS['dbs_where_create_table_allowed']
= $_SESSION[$GLOBALS['server']]['is_create_db_priv']; = PMA_cacheGet('dbs_where_create_table_allowed', true);
return; return;
} }
@@ -144,12 +144,11 @@ function PMA_analyseShowGrant()
PMA_DBI_free_result($rs_usr); PMA_DBI_free_result($rs_usr);
$_SESSION[$GLOBALS['server']]['is_create_db_priv'] = $GLOBALS['is_create_db_priv']; PMA_cacheSet('is_create_db_priv', $GLOBALS['is_create_db_priv'], true);
$_SESSION[$GLOBALS['server']]['is_process_priv'] = $GLOBALS['is_create_db_priv']; PMA_cacheSet('is_process_priv', $GLOBALS['is_process_priv'], true);
$_SESSION[$GLOBALS['server']]['is_reload_priv'] = $GLOBALS['is_create_db_priv']; PMA_cacheSet('is_reload_priv', $GLOBALS['is_reload_priv'], true);
$_SESSION[$GLOBALS['server']]['db_to_create'] = $GLOBALS['is_create_db_priv']; PMA_cacheSet('db_to_create', $GLOBALS['db_to_create'], true);
$_SESSION[$GLOBALS['server']]['dbs_where_create_table_allowed'] PMA_cacheSet('dbs_where_create_table_allowed', $GLOBALS['dbs_where_create_table_allowed'], true);
= $GLOBALS['is_create_db_priv'];
} // end function } // end function
PMA_analyseShowGrant(); PMA_analyseShowGrant();

View File

@@ -1212,20 +1212,20 @@ function PMA_showMessage($message, $sql_query = null, $type = 'notice')
*/ */
function PMA_profilingSupported() function PMA_profilingSupported()
{ {
if (! isset($_SESSION[$GLOBALS['server']]['profiling_supported'])) { if (! PMA_cacheExists('profiling_supported', true)) {
// 5.0.37 has profiling but for example, 5.1.20 does not // 5.0.37 has profiling but for example, 5.1.20 does not
// (avoid a trip to the server for MySQL before 5.0.37) // (avoid a trip to the server for MySQL before 5.0.37)
// and do not set a constant as we might be switching servers // and do not set a constant as we might be switching servers
if (defined('PMA_MYSQL_INT_VERSION') if (defined('PMA_MYSQL_INT_VERSION')
&& PMA_MYSQL_INT_VERSION >= 50037 && PMA_MYSQL_INT_VERSION >= 50037
&& PMA_DBI_fetch_value("SHOW VARIABLES LIKE 'profiling'")) { && PMA_DBI_fetch_value("SHOW VARIABLES LIKE 'profiling'")) {
$_SESSION[$GLOBALS['server']]['profiling_supported'] = true; PMA_cacheSet('profiling_supported', true, true);
} else { } else {
$_SESSION[$GLOBALS['server']]['profiling_supported'] = false; PMA_cacheSet('profiling_supported', false, true);
} }
} }
return $_SESSION[$GLOBALS['server']]['profiling_supported']; return PMA_cacheGet('profiling_supported', true);
} }
/** /**
@@ -2350,4 +2350,57 @@ function PMA_generate_slider_effect($id, $message) {
</script> </script>
<?php <?php
} }
/**
* Cache information in the session
*
* @param unknown_type $var
* @param unknown_type $val
* @param unknown_type $server
* @return mixed
*/
function PMA_cacheExists($var, $server = 0)
{
if (true === $server) {
$server = $GLOBALS['server'];
}
return isset($_SESSION['cache']['server_' . $server][$var]);
}
/**
* Cache information in the session
*
* @param unknown_type $var
* @param unknown_type $val
* @param unknown_type $server
* @return mixed
*/
function PMA_cacheGet($var, $server = 0)
{
if (true === $server) {
$server = $GLOBALS['server'];
}
if (isset($_SESSION['cache']['server_' . $server][$var])) {
return $_SESSION['cache']['server_' . $server][$var];
} else {
return null;
}
}
/**
* Cache information in the session
*
* @param unknown_type $var
* @param unknown_type $val
* @param unknown_type $server
* @return mixed
*/
function PMA_cacheSet($var, $val = null, $server = 0)
{
if (true === $server) {
$server = $GLOBALS['server'];
}
$_SESSION['cache']['server_' . $server][$var] = $val;
}
?> ?>

View File

@@ -808,9 +808,9 @@ function PMA_DBI_get_variable($var, $type = PMA_DBI_GETVAR_SESSION, $link = null
function PMA_DBI_postConnect($link, $is_controluser = false) function PMA_DBI_postConnect($link, $is_controluser = false)
{ {
if (! defined('PMA_MYSQL_INT_VERSION')) { if (! defined('PMA_MYSQL_INT_VERSION')) {
if (isset($_SESSION['PMA_MYSQL_INT_VERSION'])) { if (PMA_cacheExists('PMA_MYSQL_INT_VERSION', true)) {
define('PMA_MYSQL_INT_VERSION', $_SESSION[$GLOBALS['server']]['PMA_MYSQL_INT_VERSION']); define('PMA_MYSQL_INT_VERSION', PMA_cacheGet('PMA_MYSQL_INT_VERSION', true));
define('PMA_MYSQL_STR_VERSION', $_SESSION[$GLOBALS['server']]['PMA_MYSQL_STR_VERSION']); define('PMA_MYSQL_STR_VERSION', PMA_cacheGet('PMA_MYSQL_STR_VERSION', true));
} else { } else {
$mysql_version = PMA_DBI_fetch_value( $mysql_version = PMA_DBI_fetch_value(
'SELECT VERSION()', 0, 0, $link, PMA_DBI_QUERY_STORE); 'SELECT VERSION()', 0, 0, $link, PMA_DBI_QUERY_STORE);
@@ -825,8 +825,8 @@ function PMA_DBI_postConnect($link, $is_controluser = false)
define('PMA_MYSQL_INT_VERSION', 50015); define('PMA_MYSQL_INT_VERSION', 50015);
define('PMA_MYSQL_STR_VERSION', '5.00.15'); define('PMA_MYSQL_STR_VERSION', '5.00.15');
} }
$_SESSION[$GLOBALS['server']]['PMA_MYSQL_INT_VERSION'] = PMA_MYSQL_INT_VERSION; PMA_cacheSet('PMA_MYSQL_INT_VERSION', PMA_MYSQL_INT_VERSION, true);
$_SESSION[$GLOBALS['server']]['PMA_MYSQL_STR_VERSION'] = PMA_MYSQL_STR_VERSION; PMA_cacheSet('PMA_MYSQL_STR_VERSION', PMA_MYSQL_STR_VERSION, true);
} }
} }
@@ -1168,20 +1168,20 @@ function PMA_DBI_get_warnings($link = null)
*/ */
function PMA_isSuperuser() function PMA_isSuperuser()
{ {
if (isset($_SESSION[$GLOBALS['server']]['is_superuser'])) { if (PMA_cacheExists('is_superuser', true)) {
return $_SESSION[$GLOBALS['server']]['is_superuser']; return PMA_cacheGet('is_superuser', true);
} }
// with mysql extension, when connection failed we don't have // with mysql extension, when connection failed we don't have
// a $userlink // a $userlink
if (isset($GLOBALS['userlink'])) { if (isset($GLOBALS['userlink'])) {
$_SESSION[$GLOBALS['server']]['is_superuser'] = (bool) PMA_DBI_try_query('SELECT COUNT(*) FROM mysql.user', $r = (bool) PMA_DBI_try_query('SELECT COUNT(*) FROM mysql.user', $GLOBALS['userlink'], PMA_DBI_QUERY_STORE);
$GLOBALS['userlink'], PMA_DBI_QUERY_STORE); PMA_cacheSet('is_superuser', $r, true);
} else { } else {
$_SESSION[$GLOBALS['server']]['is_superuser'] = false; PMA_cacheSet('is_superuser', false, true);
} }
return $_SESSION[$GLOBALS['server']]['is_superuser']; return PMA_cacheGet('is_superuser', true);
} }
/** /**

View File

@@ -9,7 +9,7 @@
* *
*/ */
if (! isset($_SESSION[$GLOBALS['server']]['mysql_charsets_count'])) { if (! PMA_cacheExists('mysql_charsets_count', true)) {
$res = PMA_DBI_query('SHOW CHARACTER SET;'); $res = PMA_DBI_query('SHOW CHARACTER SET;');
$mysql_charsets = array(); $mysql_charsets = array();
@@ -55,25 +55,25 @@ if (! isset($_SESSION[$GLOBALS['server']]['mysql_charsets_count'])) {
} }
unset($key, $value); unset($key, $value);
$_SESSION[$GLOBALS['server']]['mysql_charsets'] = $GLOBALS['mysql_charsets']; PMA_cacheSet('mysql_charsets', $GLOBALS['mysql_charsets'], true);
$_SESSION[$GLOBALS['server']]['mysql_charsets_descriptions'] = $GLOBALS['mysql_charsets_descriptions']; PMA_cacheSet('mysql_charsets_descriptions', $GLOBALS['mysql_charsets_descriptions'], true);
$_SESSION[$GLOBALS['server']]['mysql_charsets_count'] = $GLOBALS['mysql_charsets_count']; PMA_cacheSet('mysql_charsets_count', $GLOBALS['mysql_charsets_count'], true);
$_SESSION[$GLOBALS['server']]['mysql_charsets_available'] = $GLOBALS['mysql_charsets_available']; PMA_cacheSet('mysql_charsets_available', $GLOBALS['mysql_charsets_available'], true);
$_SESSION[$GLOBALS['server']]['mysql_collations'] = $GLOBALS['mysql_collations']; PMA_cacheSet('mysql_collations', $GLOBALS['mysql_collations'], true);
$_SESSION[$GLOBALS['server']]['mysql_default_collations'] = $GLOBALS['mysql_default_collations']; PMA_cacheSet('mysql_default_collations', $GLOBALS['mysql_default_collations'], true);
$_SESSION[$GLOBALS['server']]['mysql_collations_flat'] = $GLOBALS['mysql_collations_flat']; PMA_cacheSet('mysql_collations_flat', $GLOBALS['mysql_collations_flat'], true);
$_SESSION[$GLOBALS['server']]['mysql_collations_count'] = $GLOBALS['mysql_collations_count']; PMA_cacheSet('mysql_collations_count', $GLOBALS['mysql_collations_count'], true);
$_SESSION[$GLOBALS['server']]['mysql_collations_available'] = $GLOBALS['mysql_collations_available']; PMA_cacheSet('mysql_collations_available', $GLOBALS['mysql_collations_available'], true);
} else { } else {
$GLOBALS['mysql_charsets'] = $_SESSION[$GLOBALS['server']]['mysql_charsets']; $GLOBALS['mysql_charsets'] = PMA_cacheGet('mysql_charsets', true);
$GLOBALS['mysql_charsets_descriptions'] = $_SESSION[$GLOBALS['server']]['mysql_charsets_descriptions']; $GLOBALS['mysql_charsets_descriptions'] = PMA_cacheGet('mysql_charsets_descriptions', true);
$GLOBALS['mysql_charsets_count'] = $_SESSION[$GLOBALS['server']]['mysql_charsets_count']; $GLOBALS['mysql_charsets_count'] = PMA_cacheGet('mysql_charsets_count', true);
$GLOBALS['mysql_charsets_available'] = $_SESSION[$GLOBALS['server']]['mysql_charsets_available']; $GLOBALS['mysql_charsets_available'] = PMA_cacheGet('mysql_charsets_available', true);
$GLOBALS['mysql_collations'] = $_SESSION[$GLOBALS['server']]['mysql_collations']; $GLOBALS['mysql_collations'] = PMA_cacheGet('mysql_collations', true);
$GLOBALS['mysql_default_collations'] = $_SESSION[$GLOBALS['server']]['mysql_default_collations']; $GLOBALS['mysql_default_collations'] = PMA_cacheGet('mysql_default_collations', true);
$GLOBALS['mysql_collations_flat'] = $_SESSION[$GLOBALS['server']]['mysql_collations_flat']; $GLOBALS['mysql_collations_flat'] = PMA_cacheGet('mysql_collations_flat', true);
$GLOBALS['mysql_collations_count'] = $_SESSION[$GLOBALS['server']]['mysql_collations_count']; $GLOBALS['mysql_collations_count'] = PMA_cacheGet('mysql_collations_count', true);
$GLOBALS['mysql_collations_available'] = $_SESSION[$GLOBALS['server']]['mysql_collations_available']; $GLOBALS['mysql_collations_available'] = PMA_cacheGet('mysql_collations_available', true);
} }
define('PMA_CSDROPDOWN_COLLATION', 0); define('PMA_CSDROPDOWN_COLLATION', 0);