MyBB Community Forums

Full Version: Improve Whose Browsing Feature
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Right now the way it processes the information is very slow if your forum has a lot of traffic. What I think should be done different is to use 2 queries instead of 1 to put together the online list. The first one is just for members. The other would be a SELECT COUNT query for getting the number of guests. This would be faster because SELECT COUNT executes much more quickly than having to cache many fields that it doesn't need.

Example for forumdisplay.php

This gets the registered users
$query = $db->query("
		SELECT s.ip, s.uid, u.username, s.time, u.invisible, u.usergroup, u.usergroup, u.displaygroup
		FROM ".TABLE_PREFIX."sessions s
		LEFT JOIN ".TABLE_PREFIX."users u ON (s.uid=u.uid)
		WHERE s.time > '$timecut' AND location1='$fid' AND nopermission != 1 AND s.uid!=0
		ORDER BY u.username ASC, s.time DESC
	");

This is for guests:

SELECT COUNT(sid) as guests
		FROM ".TABLE_PREFIX."sessions
		WHERE time > '$timecut' AND location1='$fid' AND nopermission != 1 AND uid=0

I did this to both forumdisplay.php and showthread.php and have seen a good size difference.