MyBB Community Forums

Full Version: Performance Suggestion to is_moderator
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm having a serious performance decrease with query cache and part of the issue is the is_moderator function which is widely used on MyBB pages like search, newreply, moderation, showthread, usercp, xmlhttp, and well..just about everywhere.

My current dillema seems to be that even though I use xcache and my $cache['moderators'] table is fine there are constant calls to mysql from the queries in get_moderator_permissions() function. But that function imho is not the real problem.

That function gets called from is_moderator and triggered in this code:


		if(!$fid)
		{
			$modcache = $cache->read('moderators');
			if(!empty($modcache))
			{
				foreach($modcache as $modusers)
				{
					if(isset($modusers['users'][$uid]) && $modusers['users'][$uid]['mid'])
					{
						return true;
					}
					elseif(isset($modusers['usergroups'][$user_perms['gid']]))
					{
						// Moderating usergroup
						return true;
					}
				}
			}
			return false;
		}
		else
		{
			$modperms = get_moderator_permissions($fid, $uid);

I notice that moderators cache does have FID. So why does there have to be a call to function get_moderator_permissions when a grab of the cache will suffice? All the perms required appear to be in the cache.

This line is practically worthless.
$modperms = get_moderator_permissions($fid, $uid);


So if MyBB dev team can review this code for optimization and a performance increase I'd appreciate it.

Its does appear to be redundant for forum permissions, however without more digging I can not be sure its not used for checking modCP access, etc.

edit: since canmodcp is not part of that cache and it looks like the cache and function return the same values, so i think its redundant. perhaps a better test would be to put an update cache call if the cache read that returns nothing.



Well you should review both functions in full. Basically it's a valid check but it ignores the datacache. I'm finding that a lot of the datacache used by MyBB is ignored during calls and this would help greatly reduce load if it did.
If i can get some more time I can try to look into it.

My job deals with natural disasters, so I have been going non stop since Thursday with the Japan EQ. I am lucky to find a bit of time today