Skip to content

Commit

Permalink
Added caching for current user information. The cache is dropped when…
Browse files Browse the repository at this point in the history
… the

user information is modified.  Following is the reduction in number of queries:
- summary: 226/214 -> 211/210
- report bug advanced: 53/34 -> 36/29
- report bug: 26/13 -> 10/9
- view bugs: 436/90 -> 233/86
- view bug page: 68/24 -> 35/21
- view bug advanced: 66/22 -> 33/19


git-svn-id: http://mantisbt.svn.sourceforge.net/svnroot/mantisbt/trunk@1158 f5dc347c-c33d-0410-90a0-b07cc1902cb9
  • Loading branch information
vboctor committed Jun 25, 2002
1 parent f67d998 commit f1d69dc
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 43 deletions.
8 changes: 5 additions & 3 deletions account_delete.php
Expand Up @@ -5,11 +5,11 @@
# See the README and LICENSE files for details

# --------------------------------------------------------
# $Revision: 1.8 $
# $Revision: 1.9 $
# $Author: vboctor $
# $Date: 2002-06-14 05:36:48 $
# $Date: 2002-06-25 14:23:57 $
#
# $Id: account_delete.php,v 1.8 2002-06-14 05:36:48 vboctor Exp $
# $Id: account_delete.php,v 1.9 2002-06-25 14:23:57 vboctor Exp $
# --------------------------------------------------------
?>
<?php
Expand Down Expand Up @@ -67,6 +67,8 @@
setcookie( $g_string_cookie );
setcookie( $g_project_cookie );
setcookie( $g_view_all_cookie );

drop_user_info_cache();
} # end if protected
?>
<?php print_page_top1() ?>
Expand Down
2 changes: 2 additions & 0 deletions account_update.php
Expand Up @@ -43,6 +43,8 @@
WHERE id='$c_id'";
$result = db_query( $query );
}

drop_user_info_cache();
} # end if protected

$t_redirect_url = 'account_page.php';
Expand Down
18 changes: 8 additions & 10 deletions core_email_API.php
Expand Up @@ -7,11 +7,11 @@
###########################################################################
# Email API
# -------------------------------------------------
# $Revision: 1.62 $
# $Author: jctrosset $
# $Date: 2002-06-24 10:06:18 $
# $Revision: 1.63 $
# $Author: vboctor $
# $Date: 2002-06-25 14:23:57 $
#
# $Id: core_email_API.php,v 1.62 2002-06-24 10:06:18 jctrosset Exp $
# $Id: core_email_API.php,v 1.63 2002-06-25 14:23:57 vboctor Exp $
###########################################################################
# --------------------
# check to see that the format is valid and that the mx record exists
Expand Down Expand Up @@ -263,8 +263,7 @@ function email_reset( $p_user_id, $p_password ) {
# --------------------
# send notices when a new bug is added
function email_new_bug( $p_bug_id ) {
global $g_mantis_user_table, $s_new_bug_msg,
$g_project_cookie_val;
global $s_new_bug_msg;

$t_bcc = build_bcc_list( $p_bug_id, 'email_on_new' );
email_bug_info( $p_bug_id, $s_new_bug_msg, $t_bcc );
Expand Down Expand Up @@ -322,7 +321,7 @@ function email_assign( $p_bug_id ) {
# Build the bug info part of the message
function email_build_bug_message( $p_bug_id ) {
global $g_mantis_bug_table, $g_mantis_bug_text_table,
$g_mantis_user_table, $g_mantis_project_table,
$g_mantis_project_table,
$g_complete_date_format, $g_show_view,
$g_bugnote_order, $g_path,
$s_email_reporter, $s_email_handler,
Expand Down Expand Up @@ -412,7 +411,7 @@ function email_build_bug_message( $p_bug_id ) {
# Build the bugnotes part of the message
function email_build_bugnote_message( $p_bug_id ) {
global $g_mantis_bugnote_table, $g_mantis_bugnote_text_table,
$g_mantis_user_table, $g_complete_date_format,
$g_complete_date_format,
$g_bugnote_order, $g_email_separator2;

$c_bug_id = (integer)$p_bug_id;
Expand Down Expand Up @@ -452,8 +451,7 @@ function email_build_bugnote_message( $p_bug_id ) {
# --------------------
# Send bug info to reporter and handler
function email_bug_info( $p_bug_id, $p_message, $p_headers='' ) {
global $g_mantis_user_table, $g_mantis_bug_table, $g_mantis_project_table,
$g_to_email, $g_use_bcc;
global $g_to_email, $g_use_bcc;

# build subject
$p_subject = email_build_subject( $p_bug_id );
Expand Down
3 changes: 1 addition & 2 deletions core_html_API.php
Expand Up @@ -226,8 +226,7 @@ function print_html_bottom() {
# prints the user that is logged in and the date/time
# it also creates the form where users can switch projects
function print_login_info() {
global $g_mantis_user_table,
$g_string_cookie_val, $g_project_cookie_val,
global $g_string_cookie_val, $g_project_cookie_val,
$g_complete_date_format,
$s_switch, $s_logged_in_as, $s_all_projects,
$s_access_levels_enum_string,
Expand Down
4 changes: 2 additions & 2 deletions core_summary_API.php
Expand Up @@ -193,7 +193,7 @@ function print_developer_summary() {
# --------------------
# print bug counts by reporter id
function print_reporter_summary() {
global $g_mantis_bug_table, $g_mantis_user_table,
global $g_mantis_bug_table,
$g_primary_color1, $g_primary_color2,
$g_reporter_summary_limit,
$g_project_cookie_val,
Expand Down Expand Up @@ -267,7 +267,7 @@ function print_reporter_summary() {
# --------------------
# print a bug count per category
function print_category_summary() {
global $g_mantis_bug_table, $g_mantis_user_table, $g_mantis_project_table,
global $g_mantis_bug_table, $g_mantis_project_table,
$g_mantis_project_category_table, $g_project_cookie_val,
$g_primary_color1, $g_primary_color1,
$g_summary_pad, $g_summary_product_colon_category;
Expand Down
47 changes: 28 additions & 19 deletions core_user_API.php
Expand Up @@ -14,8 +14,7 @@
# if $p_redirect_url is specifed then redirect them to that page
function login_cookie_check( $p_redirect_url='', $p_return_page='' ) {
global $g_string_cookie_val, $g_project_cookie_val,
$g_hostname, $g_db_username, $g_db_password, $g_database_name,
$g_mantis_user_table, $REQUEST_URI;
$REQUEST_URI;

# if logged in
if ( !empty( $g_string_cookie_val ) ) {
Expand Down Expand Up @@ -53,9 +52,7 @@ function login_cookie_check( $p_redirect_url='', $p_return_page='' ) {
# also sets the last time they visited
# otherwise redirects to the login page
function index_login_cookie_check( $p_redirect_url='' ) {
global $g_string_cookie_val, $g_project_cookie_val,
$g_hostname, $g_db_username, $g_db_password, $g_database_name,
$g_mantis_user_table;
global $g_string_cookie_val, $g_project_cookie_val;

# if logged in
if ( !empty( $g_string_cookie_val ) ) {
Expand Down Expand Up @@ -90,9 +87,7 @@ function index_login_cookie_check( $p_redirect_url='' ) {
# Only check to see if the user is logged in
# redirect to logout_page if fail
function login_user_check_only() {
global $g_string_cookie_val, $g_project_cookie_val,
$g_hostname, $g_db_username, $g_db_password, $g_database_name,
$g_mantis_user_table;
global $g_string_cookie_val;

# if logged in
if ( !empty( $g_string_cookie_val ) ) {
Expand Down Expand Up @@ -164,6 +159,8 @@ function is_password_match( $f_username, $p_test_password, $p_password ) {
function increment_login_count( $p_id ) {
global $g_mantis_user_table;

drop_user_info_cache();

$c_id = (integer)$p_id;

$query = "UPDATE $g_mantis_user_table
Expand Down Expand Up @@ -570,22 +567,32 @@ function get_effective_access_level( $p_user_id=0, $p_project_id=-1 ) {
}
}
# --------------------
# Flush user information cache. Should be called when the user information
# is changed.
function drop_user_info_cache( ) {
global $g_current_user_info;
unset ( $g_current_user_info );
}
# --------------------
###########################################################################
# User Information API
###########################################################################
# --------------------
# Returns the specified field of the currently logged in user, otherwise 0
function get_current_user_field( $p_field_name ) {
global $g_string_cookie_val, $g_mantis_user_table;
global $g_string_cookie_val, $g_mantis_user_table, $g_current_user_info;

# if logged in
if ( isset( $g_string_cookie_val ) ) {
# get user info
$query = "SELECT $p_field_name
FROM $g_mantis_user_table
WHERE cookie_string='$g_string_cookie_val'";
$result = db_query( $query );
return db_result( $result, 0 );
if ( !isset ( $g_current_user_info[ $p_field_name ] ) ) {
# get user info
$query = "SELECT *
FROM $g_mantis_user_table
WHERE cookie_string='$g_string_cookie_val'";
$result = db_query( $query );
$g_current_user_info = db_fetch_array ( $result );
}
return $g_current_user_info [ $p_field_name ];
} else {
return 0;
}
Expand Down Expand Up @@ -616,10 +623,10 @@ function get_user_info_by_id_arr( $p_user_id ) {

$c_user_id = (integer)$p_user_id;

$query = "SELECT *
FROM $g_mantis_user_table
WHERE id='$c_user_id'";
$result = db_query( $query );
$query = "SELECT * " .
"FROM $g_mantis_user_table " .
"WHERE id='$c_user_id'";
$result = db_query( $query );
return db_fetch_array( $result );
}
# --------------------
Expand Down Expand Up @@ -713,6 +720,8 @@ function get_user_field( $p_user_id, $p_field ) {
# Update the last_visited field to be NOW()
function login_update_last_visit( $p_string_cookie_val ) {
global $g_mantis_user_table;

drop_user_info_cache();

$c_string_cookie_val = addslashes($p_string_cookie_val);

Expand Down
2 changes: 2 additions & 0 deletions manage_create_new_user.php
Expand Up @@ -85,6 +85,8 @@
'$g_default_email_on_priority', '$g_default_language')";
$result = db_query($query);

drop_user_info_cache();

$t_redirect_url = 'manage_page.php';
?>
<?php print_page_top1() ?>
Expand Down
2 changes: 2 additions & 0 deletions manage_user_delete.php
Expand Up @@ -34,6 +34,8 @@
FROM $g_mantis_project_user_list_table
WHERE user_id='$c_id'";
$result = db_query( $query );

drop_user_info_cache();
}

$t_redirect_url = 'manage_page.php';
Expand Down
7 changes: 1 addition & 6 deletions manage_user_page.php
Expand Up @@ -8,14 +8,9 @@
<?php login_cookie_check() ?>
<?php
check_access( ADMINISTRATOR );
$c_id = (integer)$f_id;

# grab user data and prefix with u_
$query = "SELECT *
FROM $g_mantis_user_table
WHERE id='$c_id'";
$result = db_query($query);
$row = db_fetch_array($result);
$row = get_user_info_by_id_arr( $f_id );
extract( $row, EXTR_PREFIX_ALL, 'u' );
?>
<?php print_page_top1() ?>
Expand Down
2 changes: 2 additions & 0 deletions manage_user_reset.php
Expand Up @@ -44,6 +44,8 @@
WHERE id='$c_id'";
$result = db_query( $query );
}

drop_user_info_cache();
}

$t_redirect_url = 'manage_page.php';
Expand Down
1 change: 1 addition & 0 deletions manage_user_update.php
Expand Up @@ -45,6 +45,7 @@
}

$result = db_query( $query );
drop_user_info_cache();
$t_redirect_url = 'manage_page.php';
?>
<?php print_page_top1() ?>
Expand Down
2 changes: 1 addition & 1 deletion summary_graph_functions.php
Expand Up @@ -218,7 +218,7 @@ function graph_reporter_summary( ){


function create_category_summary() {
global $g_mantis_bug_table, $g_mantis_user_table,
global $g_mantis_bug_table,
$g_mantis_project_category_table, $g_project_cookie_val,
$category_name, $category_bug_count;

Expand Down

0 comments on commit f1d69dc

Please sign in to comment.