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;
  }
CommentFileSizeAuthor
fixes.patch1.99 KBR.Muilwijk

Comments

R.Muilwijk’s picture

Category: bug » feature
Status: Active » Needs review
somebodysysop’s picture

Apparently someone has tried the patch into this problem: http://drupal.org/node/252663

somebodysysop’s picture

Status: Needs review » Postponed

Going to get to this. Had to get other updates to module released.

somebodysysop’s picture

Assigned: Unassigned » somebodysysop
Status: Postponed » Postponed (maintainer needs more info)

I am interested in pursuing the "$querie_results" idea. However, we have this issue here: http://drupal.org/node/252663

Do you have any suggestions?

sun’s picture

Status: Postponed (maintainer needs more info) » Closed (won't fix)

After 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.