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

klktrk - November 15, 2008 - 01:47
Project:Buddylist
Version:HEAD
Component:Code
Category:bug report
Priority:critical
Assigned:Unassigned
Status:needs review
Description

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.

AttachmentSize
buddylist_improve_actions_performance.patch755 bytes

#1

klktrk - November 15, 2008 - 01:49
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.

#2

klktrk - January 12, 2009 - 19:00

Bouncing. Anybody there?

 
 

Drupal is a registered trademark of Dries Buytaert.