Improved sql cache to permit make cache of several databases TICKETS #3581
This commit is contained in:
parent
c1ca17eac7
commit
6cdf363b27
|
@ -32,7 +32,9 @@ echo '</a><br />';
|
|||
echo '<a class="white footer">'. __('Page generated at') . ' '. ui_print_timestamp ($time, true, array ("prominent" => "timestamp")); //Always use timestamp here
|
||||
echo '</a>';
|
||||
if (isset ($config['debug'])) {
|
||||
echo ' - Saved '.format_numeric ($sql_cache["saved"]).' Queries';
|
||||
$cache_info = array();
|
||||
$cache_info = db_get_cached_queries();
|
||||
echo ' - Saved '.$cache_info[0].' Queries';
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -35,6 +35,8 @@ function mysql_connect_db($host = null, $db = null, $user = null, $pass = null,
|
|||
return false;
|
||||
}
|
||||
|
||||
db_change_cache_id ($db, $host);
|
||||
|
||||
mysql_select_db($db, $connect_id);
|
||||
return $connect_id;
|
||||
}
|
||||
|
@ -287,9 +289,9 @@ function mysql_db_process_sql($sql, $rettype = "affected_rows", $dbconnection =
|
|||
if ($sql == '')
|
||||
return false;
|
||||
|
||||
if ($cache && ! empty ($sql_cache[$sql])) {
|
||||
$retval = $sql_cache[$sql];
|
||||
$sql_cache['saved']++;
|
||||
if ($cache && ! empty ($sql_cache[$sql_cache['id']][$sql])) {
|
||||
$retval = $sql_cache[$sql_cache['id']][$sql];
|
||||
$sql_cache['saved'][$sql_cache['id']]++;
|
||||
db_add_database_debug_trace ($sql);
|
||||
}
|
||||
else {
|
||||
|
@ -335,7 +337,7 @@ function mysql_db_process_sql($sql, $rettype = "affected_rows", $dbconnection =
|
|||
}
|
||||
|
||||
if ($cache === true)
|
||||
$sql_cache[$sql] = $retval;
|
||||
$sql_cache[$sql_cache ['id']][$sql] = $retval;
|
||||
mysql_free_result ($result);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,6 +45,8 @@ function oracle_connect_db($host = null, $db = null, $user = null, $pass = null,
|
|||
$date_format = oci_parse($connect_id , 'alter session set NLS_DATE_FORMAT =\'YYYY-MM-DD HH24:MI:SS\'');
|
||||
$decimal_separator = oci_parse($connect_id , 'alter session set NLS_NUMERIC_CHARACTERS =\'.,\'');
|
||||
|
||||
db_change_cache_id($host, $db);
|
||||
|
||||
oci_execute($datetime_tz_format);
|
||||
oci_execute($datetime_format);
|
||||
oci_execute($date_format);
|
||||
|
@ -224,9 +226,9 @@ function oracle_db_process_sql($sql, $rettype = "affected_rows", $dbconnection =
|
|||
if ($sql == '')
|
||||
return false;
|
||||
|
||||
if ($cache && ! empty ($sql_cache[$sql])) {
|
||||
$retval = $sql_cache[$sql];
|
||||
$sql_cache['saved']++;
|
||||
if ($cache && ! empty ($sql_cache[$sql_cache['id']][$sql])) {
|
||||
$retval = $sql_cache[$sql_cache['id']][$sql];
|
||||
$sql_cache['saved'][$sql_cache['id']]++;
|
||||
db_add_database_debug_trace ($sql);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -37,6 +37,8 @@ function postgresql_connect_db($host = null, $db = null, $user = null, $pass = n
|
|||
if (! $connect_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
db_change_cache_id($host, $db);
|
||||
|
||||
return $connect_id;
|
||||
}
|
||||
|
@ -200,9 +202,9 @@ function postgresql_db_process_sql($sql, $rettype = "affected_rows", $dbconnecti
|
|||
if ($sql == '')
|
||||
return false;
|
||||
|
||||
if ($cache && ! empty ($sql_cache[$sql])) {
|
||||
$retval = $sql_cache[$sql];
|
||||
$sql_cache['saved']++;
|
||||
if ($cache && ! empty ($sql_cache[$sql_cache['id']][$sql])) {
|
||||
$retval = $sql_cache[$sql_cache['id']][$sql];
|
||||
$sql_cache['saved'][$sql_cache['id']]++;
|
||||
db_add_database_debug_trace ($sql);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -223,7 +223,7 @@ function db_logoff ($id_user, $ip) {
|
|||
db_pandora_audit("Logoff", "Logged out", $id_user, $ip);
|
||||
}
|
||||
|
||||
$sql_cache = array ('saved' => 0);
|
||||
$sql_cache = array ('saved' => array());
|
||||
|
||||
/**
|
||||
* Get the first value of the first row of a table in the database.
|
||||
|
@ -613,7 +613,40 @@ function db_add_database_debug_trace ($sql, $result = false, $affected = false,
|
|||
function db_clean_cache() {
|
||||
global $sql_cache;
|
||||
|
||||
$sql_cache = array ('saved' => 0);
|
||||
$sql_cache = array ('saved' => array ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the sql cache id to another value
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
function db_change_cache_id($name, $host) {
|
||||
global $sql_cache;
|
||||
|
||||
// Update the sql cache identification
|
||||
$sql_cache['id'] = $name . "_" . $host;
|
||||
if (!isset ($sql_cache['saved'][$sql_cache['id']])){
|
||||
$sql_cache['saved'][$sql_cache['id']] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total cached queries and the databases checked
|
||||
*
|
||||
* @return (total_queries, total_dbs)
|
||||
*/
|
||||
function db_get_cached_queries() {
|
||||
global $sql_cache;
|
||||
|
||||
$total_saved = 0;
|
||||
$total_dbs = 0;
|
||||
foreach ($sql_cache['saved'] as $saver) {
|
||||
$total_saved += format_numeric($saver);
|
||||
$total_dbs++;
|
||||
}
|
||||
|
||||
return array ($total_saved, $total_dbs);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -54,7 +54,7 @@ if (!empty ($module)) {
|
|||
|
||||
// Disable SQL cache
|
||||
global $sql_cache;
|
||||
$sql_cache = array ('saved' => 0);
|
||||
$sql_cache = array ('saved' => array());
|
||||
|
||||
|
||||
//Convert start time and end time to unix timestamps
|
||||
|
|
|
@ -53,7 +53,7 @@ if (!empty ($module)) {
|
|||
|
||||
// Disable SQL cache
|
||||
global $sql_cache;
|
||||
$sql_cache = array ('saved' => 0);
|
||||
$sql_cache = array ('saved' => array());
|
||||
|
||||
|
||||
//Convert start time and end time to unix timestamps
|
||||
|
|
|
@ -68,7 +68,7 @@ if (!empty ($export_btn) && !empty ($module)) {
|
|||
|
||||
// Disable SQL cache
|
||||
global $sql_cache;
|
||||
$sql_cache = array ('saved' => 0);
|
||||
$sql_cache = array ('saved' => array());
|
||||
|
||||
|
||||
//Convert start time and end time to unix timestamps
|
||||
|
|
Loading…
Reference in New Issue