Dunk this into profile module's hook_user to see:

/**
 * Implementation of hook_user().
 */
function profile_user($type, &$edit, &$user, $category = NULL) {
  
  
  if ($type == 'load') {
  static $count;
  $count++;
  dsm($count);    
  }

The count goes up to 9, then to 15 on a page refresh suggesting stuff happens in the theme layer too.

Comments

dawehner’s picture

The problem here is that user_load has no static cache, so everything which does a user_load run's the hook.

I think this is not fixable on d6, because it could change existing behavior.
But this is already fixed on d7.

clemens.tolboom’s picture

@dereine: Were is this fixed in D7

If have this multiple load for

function mymodule_menu() {
  $items['mymodule/%mymodule_item'] = array(...)
  return $items;
}

// Gets called 4 times
function mymodule_item_load() {
  dsm('called');
}

I found out

function function _menu_load_objects(&$item, &$map)

is called 4 times too. Done by a mixture of

function _menu_translate(&$router_item, $map, $to_arg = FALSE) {

and

function _menu_link_translate(&$item, $translate = FALSE) {

Should I report a new issue?

dawehner’s picture

Well in d7 user_load uses user_load_multiple which uses entity_load which has a static cache.

NROTC_Webmaster’s picture

Is this still an issue or can it be closed?

ispboy’s picture

Issue summary: View changes

In most of cases, we pass $uid to user_load($user_info), so i hack the user.module to build a static array keeping the result with $uid key. it works!

...
  static $uid_cache = array();
  $is_uid = FALSE;

  if (is_numeric($user_info)) {
    if (array_key_exists($user_info, $uid_cache)) {
        return $uid_cache[$user_info];
    }
    $is_uid = TRUE;

    $user_info = array('uid' => $user_info);
  }
...
...

  if ($is_uid && $user) {
    $uid_cache[$user->uid] = $user;
  }

  return $user;
}

Status: Active » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.