Skip to:
Content

Opened 5 years ago

Closed 5 years ago

Last modified 4 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: 0.9.0.6
Component: Back-end Keywords:
Cc:

Description

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;

to:

	$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_ 5 years ago.

Download all attachments as: .zip

Change History (4)

_ck_5 years ago

comment:1 sambauers5 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.

comment:2 sambauers5 years ago

  • Milestone set to 0.9.0.7

This is already cached in 1.0 via BackPress

comment:3 matt4 years ago

  • Milestone changed from 0.9.0.7 to 1.0.3

Milestone 0.9.0.7 deleted

Note: See TracTickets for help on using tickets.