Skip to:

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#1174 closed enhancement (fixed)

wasted mysql query for logged in users can be eliminated

Reported by: _ck_ Owned by:
Milestone: 1.0.3 Priority: normal
Severity: normal Version:
Component: Back-end Keywords:


This is for 0.9 branch only, unfortunately this cannot be taken advantage of for 1.0 because the process is buried in BackPress (but the concept could still be applied with a bit extra work).

A query is wasted for every page load for every logged in user because while the row is located for the user by name in function get_user_by_name based on what's in the cookie - the user is not loaded at that time. Instead the ID is passed to yet another query to load the user.

This can be easily fixed at the bottom of
function wp_validate_auth_cookie($cookie = '') {

change from:

	$user = bb_get_user_by_name($username);
	if ( ! $user )
		return false;

	return $user->ID;


	$username = sanitize_user( $username, true );
	global $bbdb;
	if ( $user = $bbdb->get_row( $bbdb->prepare( "SELECT * FROM $bbdb->users WHERE user_login = %s", $username ) ) ) {		
		bb_append_meta( $user, 'user' );
	if ( empty($user->ID) ) {return false;}

	return $user->ID;

Plugin attached to provide the entire functionality.

Attachments (1)

_get-user-by-name.php (1.1 KB) - added by _ck_ 6 years ago.

Download all attachments as: .zip

Change History (4)

#1 @sambauers
6 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [2346]) branches 0.9: Remove a query from each pageload. Props _ck_. Fixes #1174.

#2 @sambauers
6 years ago

  • Milestone set to

This is already cached in 1.0 via BackPress

#3 @matt
6 years ago

  • Milestone changed from to 1.0.3

Milestone deleted

Note: See TracTickets for help on using tickets.