unified cache_userdata indexes by referencing user_login to ID, got rid of the useless, and broken, get_userid (get_userdatabylogin provides the same functionnality anyway)

git-svn-id: http://svn.automattic.com/wordpress/trunk@2353 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
michelvaldrighi 2005-02-16 14:29:55 +00:00
parent 78842f0672
commit 8e770d3e6e
1 changed files with 8 additions and 18 deletions

View File

@ -185,8 +185,8 @@ function get_userdata($userid) {
global $wpdb, $cache_userdata;
$userid = (int) $userid;
if ( empty($cache_userdata[$userid]) && $userid != 0) {
$cache_userdata[$userid] =
$wpdb->get_row("SELECT * FROM $wpdb->users WHERE ID = '$userid'");
$cache_userdata[$userid] = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE ID = $userid");
$cache_userdata[$cache_userdata[$userid]->user_login] =& $cache_userdata[$userid];
}
return $cache_userdata[$userid];
@ -196,28 +196,17 @@ function get_userdata($userid) {
if ( !function_exists('get_userdatabylogin') ) {
function get_userdatabylogin($user_login) {
global $cache_userdata, $wpdb;
if ( !empty($user_login) && empty($cache_userdata["$user_login"]) ) {
$user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE user_login = '$user_login'");
$cache_userdata["$user_login"] = $user;
if ( !empty($user_login) && empty($cache_userdata[$user_login]) ) {
$user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE user_login = '$user_login'"); /* todo: get rid of this intermediate var */
$cache_userdata[$user->ID] = $user;
$cache_userdata[$user_login] =& $cache_userdata[$user->ID];
} else {
$user = $cache_userdata["$user_login"];
$user = $cache_userdata[$user_login];
}
return $user;
}
}
function get_userid($user_login) {
global $cache_userdata, $wpdb;
if ( !empty($user_login) && empty($cache_userdata["$user_login"]) ) {
$user_id = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_login = '$user_login'");
$cache_userdata["$user_login"] = $user_id;
} else {
$user_id = $cache_userdata["$user_login"];
}
return $user_id;
}
function get_usernumposts($userid) {
global $wpdb;
return $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = '$userid'");
@ -1075,6 +1064,7 @@ function update_user_cache() {
if ( $users = $wpdb->get_results("SELECT * FROM $wpdb->users WHERE user_level > 0") ) :
foreach ($users as $user) :
$cache_userdata[$user->ID] = $user;
$cache_userdata[$user->user_login] =& $cache_userdata[$user->ID];
endforeach;
return true;
else: