Even when buddylist groups are not enabled, the function buddylist_get_buddies queries the groups table. On friends based social networking site, this can result in a lot of unnecessary load on the db.

I'm attaching a patch. Since my site's not using groups, I haven't tested to see how this works if you have groups turned on. The logic seems sound, but be sure to test first.

CommentFileSizeAuthor
buddylist.module_3.patch567 bytesgwen

Comments

stroobl’s picture

We implemented this patch and the performance gain is huge. It can save you hundreds of SQL queries for every pageview.
In addition to the above patch, we also added a check to make sure buddylist queries are only executed when somebody is on a profile/buddylist page. Buddylist was checking buddy info for every article poster, while that info was displayed nowhere in our situation (maybe it's usefull in some cases, I'm not sure about that). But when you have an index-page with ten or more posts and the posters have lot's of buddies, that's really painfull.

This is what we changed:

671c671
< if (!isset($buddies[$key][$uid])) {
---
> if (!isset($buddies[$key][$uid]) && (arg(0) == 'buddy' || arg(0) == 'buddylist' || arg(0) == 'user') ) {
681,682c681,684
< $buddies[$key][$uid][$row->buddy]['groups'] = buddylist_get_buddy_groups($uid, $row->buddy);
< $buddies[$key][$uid][$row->buddy]['online'] = 0;
---
> if (variable_get('buddylist_buddygroups', FALSE)) {
> $buddies[$key][$uid][$row->buddy]['groups'] = buddylist_get_buddy_groups($uid, $row->buddy);
> }
> $buddies[$key][$uid][$row->buddy]['online'] = 0;
828c830

And the result:
Index-page before:
Executed 968 queries in 638.08 milliseconds.
Page execution time was 1719.58 ms.

After patch:
Executed 434 queries in 78.85 milliseconds.
Page execution time was 724.56 ms.

Profile-page of a user with lot's of buddies before:
Vorige week donderdag:
Executed 3636 queries in 477.09 milliseconds.
Page execution time was 1380.71 ms.

After patch:
Executed 411 queries in 133.83 milliseconds.
Page execution time was 733.8 ms.

robertdouglass’s picture

Status: Needs review » Fixed

@gwen, thanks, fixed.
@lstroobant, please open another issue and provide a patch file.
@both please make diffs using the -u flag for readability. Thanks.

Anonymous’s picture

Status: Fixed » Closed (fixed)