Closed (won't fix)
Project:
OG User Roles
Version:
5.x-2.8
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Reporter:
Created:
24 Apr 2008 at 13:43 UTC
Updated:
5 Dec 2009 at 17:45 UTC
At the moment you get all the user roles for ALL user_loads:
// Add the group roles to $user->roles if this is a group
// This should only be effective until the next global $user call
if ($op == 'load') {
$roles = og_user_roles_all_roles($user); // This returns normal $user->roles and includes OG roles if any
$user->roles = $roles;
} // end $op load
However it is only necessary if you are the current user or want to display the users roles. Because the chance you want to display the users roles is not that big I would normally only want to get the roles if it were the current user.
Maybe make it something like this:
// Add the group roles to $user->roles if this is a group
// This should only be effective until the next global $user call
if ($op == 'load' && ($GLOBALS['user']->uid == $user->uid || variable_get('user_roles_always_get_roles', 0))) {
$roles = og_user_roles_all_roles($user); // This returns normal $user->roles and includes OG roles if any
$user->roles = $roles;
} // end $op load
Another little performance gain
$query = 'SELECT r.rid, r.name FROM {role} r INNER JOIN {og_users_roles} ogr ON r.rid = ogr.rid INNER JOIN {og_uid} ogu ON ogu.uid = ogr.uid AND ogu.nid = ogr.gid WHERE ogr.uid = %d AND ogr.gid = %d AND ogu.is_active = 1';
$results = db_query($query, $uid, $gid);
//
// Create an array of these roles;
//
while ($row = db_fetch_array($results)) {
$x1 = $row['rid'];
$ogroles[$x1] = $row['name'];
}
Replace with:
static $querie_results;
if (isset($querie_results[$uid.'_'.$gid])) {
$ogroles = $querie_results[$uid.'_'.$gid];
}
else {
$query = 'SELECT r.rid, r.name FROM {role} r INNER JOIN {og_users_roles} ogr ON r.rid = ogr.rid INNER JOIN {og_uid} ogu ON ogu.uid = ogr.uid AND ogu.nid = ogr.gid WHERE ogr.uid = %d AND ogr.gid = %d AND ogu.is_active = 1';
$results = db_query($query, $uid, $gid);
//
// Create an array of these roles;
//
while ($row = db_fetch_array($results)) {
$x1 = $row['rid'];
$ogroles[$x1] = $row['name'];
}
$querie_results[$uid.'_'.$gid] = $ogroles;
}
| Comment | File | Size | Author |
|---|---|---|---|
| fixes.patch | 1.99 KB | R.Muilwijk |
Comments
Comment #1
R.Muilwijk commentedComment #2
somebodysysop commentedApparently someone has tried the patch into this problem: http://drupal.org/node/252663
Comment #3
somebodysysop commentedGoing to get to this. Had to get other updates to module released.
Comment #4
somebodysysop commentedI am interested in pursuing the "$querie_results" idea. However, we have this issue here: http://drupal.org/node/252663
Do you have any suggestions?
Comment #5
sunAfter the rise of the rewritten OGUR 4.x for Drupal 6, in which many unrelated features of OGUR were removed, and nearing a release of Drupal 7, I'm closing down old issues.