diff --git a/checkin_notes b/checkin_notes index 36d16844f9..b93649708e 100755 --- a/checkin_notes +++ b/checkin_notes @@ -2438,3 +2438,17 @@ Charlie 13 Mar 2007 gui_rpc_server_ops.C clientgui/ ViewProjectsGrid.cpp + +Matt 14 Mar 2007 + - updated db_init and db_init_aux code in util.inc, db.inc to enable + possible use of replica (i.e. read-only) database (for pages that + lookup stats, print profiles, etc. but don't make any updates). + Implemented in top_{users,teams,hosts}.php + + html/inc + db.inc + util.inc + html/user + top_users.php + top_hosts.php + top_teams.php diff --git a/html/inc/db.inc b/html/inc/db.inc index 505882d484..24242b7c76 100644 --- a/html/inc/db.inc +++ b/html/inc/db.inc @@ -5,11 +5,17 @@ require_once('../inc/util.inc'); // database-related functions. // Presentation code (HTML) shouldn't be here -function db_init_aux() { +function db_init_aux($try_replica=false) { $config = get_config(); $user = parse_config($config, ""); $pass = parse_config($config, ""); - $host = parse_config($config, ""); + $host = null; + if ($try_replica == true) { + $host = parse_config($config, ""); + } + if ($host == null) { + $host = parse_config($config, ""); + } if ($host == null) { $host = "localhost"; } diff --git a/html/inc/util.inc b/html/inc/util.inc index 5d58fabbcf..01440bff84 100644 --- a/html/inc/util.inc +++ b/html/inc/util.inc @@ -8,7 +8,13 @@ require_once("../inc/translation.inc"); $generating_xml = false; -function db_init() { +// db_init +// Connects to database server and selects database as noted in config.xml +// (Or, in some cases, if only read-only access is necessary, tries instead +// to connect to replica database server noted in tag. If +// this tag doesn't exist, db_init will revert to connecting to .) +// +function db_init($try_replica=false) { if (web_stopped()) { page_head("Not available"); echo "This page requires database access. @@ -18,7 +24,7 @@ function db_init() { page_tail(); exit(); } - $retval = db_init_aux(); + $retval = db_init_aux($try_replica); if ($retval == 1) { echo "Unable to connect to database - please try again later\n"; echo "Error: ", mysql_errno(), mysql_error(); diff --git a/html/user/top_hosts.php b/html/user/top_hosts.php index 7833764917..c143c228d3 100644 --- a/html/user/top_hosts.php +++ b/html/user/top_hosts.php @@ -28,7 +28,7 @@ if ($offset < 1000) { require_once("../inc/db.inc"); require_once("../inc/host.inc"); -db_init(); +db_init(true); page_head("Top computers"); if ($sort_by == "total_credit") { $sort_clause = "total_credit desc"; diff --git a/html/user/top_teams.php b/html/user/top_teams.php index 1078708d6e..e1123e29cf 100644 --- a/html/user/top_teams.php +++ b/html/user/top_teams.php @@ -62,7 +62,7 @@ if ($offset < ITEM_LIMIT) { if ($cacheddata){ //If we have got the data in cache $data = store_to_teams($cacheddata); // use the cached data } else { //if not do queries etc to generate new data - db_init(); + db_init(true); $data = get_top_teams($offset,$sort_by,$type); // We need to calculate nusers before storing into the cache diff --git a/html/user/top_users.php b/html/user/top_users.php index 9e40469b1b..45ca9a4abc 100644 --- a/html/user/top_users.php +++ b/html/user/top_users.php @@ -45,7 +45,7 @@ if ($offset < ITEM_LIMIT) { if ($cacheddata){ //If we have got the data in cache $data = store_to_participants($cacheddata); // use the cached data } else { //if not do queries etc to generate new data - db_init(); + db_init(true); $data = get_top_participants($offset,$sort_by); set_cache_data(participants_to_store($data),$cache_args); //save data in cache };