Low / 0 query way to get user permission in profile area

tenants

Well-known member
I'm using template hooks to add a tab to the profile area, this requires 2 template hooks

1) For the tab name (member_view_tabs_heading)
2) For the tab content (member_view_tabs_content)

To get the permissions of the user (profile), it looks like I may need to do at least 1 additional query since looking at
Code:
$globalParams = $template->getParams();
global_permission_cache is not available for the ['user'] only the ['visitor']

To get the user permissions of the user, I could use:

Code:
$globalParams = $template->getParams();
$userModel = XenForo_Model::create('XenForo_Model_User');
$profileUser = $userModel->getUserById($globalParams['user']['user_id'], array(
         'join' => XenForo_Model_User::FETCH_USER_PERMISSIONS
   ));

But, this is probably unnecessary... and we don't need to get the user again (just the permissions)
Also, this would need to be applied in 2 areas:
member_view_tabs_heading and member_view_tabs_content, since if it wasn't applied in the content, the li order will go out of synch for the Tabs data-panes functionality (the ajax loading of the Tabs)

This would boost the query count for the profile area from 15 to 17 (that's before creating templates)

For the tab title and url, I am avoiding creating the template and getting the request path from the global params:

Code:
$globalParams = $template->getParams();
$requestPaths = $globalParams["requestPaths"];
$contents = '<li><a href="' . $requestPaths['requestUri'] . '#tabname">tabname</a></li>'. $contents;

Not using $template->create seems to reduce the query count by one (and we no longer need to cache the template... this is good for titles / simple bits of data)


I'm wondering what others have done when needing to get the permissions of the profile user you are looking at (not the visitor) ... at most I think 1 additional query is needed (it's possible that the permissions of the user is already available, but I couldn't find it)


I've noticed that if people aren't careful in this area, adding bits (such as creating templates, query for user permissions, and getting counts for the stats) can quickly bloat this area, so I think a 0-1 query overhead for this area is important (even if we need to get the user permissions)

I have seen at least 2 add-ons increase this area from 15 to 20 queries (both add-ons together increase it from 15 to 25... that's hideous for just 2 add-ons)
 
Last edited:
I've just seen that both member_view_tabs_heading and member_view_tabs_content pass $user into them:

<xen:hook name="member_view_tabs_heading" params="{xen:array 'user={$user}'}" />
<xen:hook name="member_view_tabs_content" params="{xen:array 'user={$user}'}" />

This is the user that you are viewing

But there are no $user['permissions']
 
Last edited:
Update:

I'm now using a global static param, so I only increase the query count by one (the permissions are just checked once, covering both template hooks).
If you don't need to check permissions of the profile you are looking at, you should be able to get your add-on down to 0 queries overhead for the profile area
 
I've just seen that both member_view_tabs_heading and member_view_tabs_content pass $user into them:

<xen:hook name="member_view_tabs_heading" params="{xen:array 'user={$user}'}" />
<xen:hook name="member_view_tabs_content" params="{xen:array 'user={$user}'}" />

This is the user that you are viewing

But there are no $user['permissions']
Not all $user contains a full user array.
 
Top Bottom