The function buddylist_get_buddy_actions contains a simple flip in logic that almost doubles the load of each user's profile page when viewed by a logged in user.

There is no need to grab the viewing user's buddy list, since if the viewing user *is* a buddy already, the viewing
user's id should be in the viewed user's buddy list, since the lists are reciprocal.
This should give a big boost to busy sites.

The attached patch simply flips the logic from this:

  else if (in_array($viewed_user->uid, array_keys(buddylist_get_buddies($viewing_user->uid)))) {
    $actions[] = theme('remove_from_buddylist_link', $viewed_user);
  }

to this:

  else if (in_array($viewing_user->uid, array_keys(buddylist_get_buddies($viewed_user->uid)))) {
    $actions[] = theme('remove_from_buddylist_link', $viewed_user);
  }

We can't for the life of us figure out why this was done in the first place, or are we missing something?

Thanks.

CommentFileSizeAuthor
buddylist_improve_actions_performance.patch755 bytesapotek
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

apotek’s picture

Title: Performance Improvement: Eliminate the load of the viewing user's buddies in buddylist_get_buddy_actions » Performance Improvement: Eliminate the unnecessary load of the viewing user's buddies in buddylist_get_buddy_actions

Title edit.

apotek’s picture

Bouncing. Anybody there?