On sites that have a lot of user_load() calls the user badges modules seems to really tally up a large amount of queries due to it's loading operation in hook_user. It doesn't always make sense for users of this module to load badges on any page except the user profile page. So this patch adds a setting into user badges that allows it to be toggled on and off, essentially giving the user an option to save on precious query calls. Please review and let me know if you find anything off-mark with this. Thanks!

CommentFileSizeAuthor
user_badges_profileonly.patch1.58 KBrobphillips
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Richard Blackborder’s picture

Status: Needs review » Needs work

I'm not sure this is the best approach because it will break any modules that need to load badges on other pages. It might be better to use Drupal's cache system (does D5 have this?) so that functionality isn't reduced, or add a hook or something so that other modules can force a load on other pages.

NancyDru’s picture

Assigned: robphillips » NancyDru
Status: Needs work » Needs review

Try this one. It's based on 6.x-1.x-dev, but the code should work on 5.x. It uses simple static caching to avoid loading stuff that has already been loaded before and shouldn't break anything.

NancyDru’s picture

Oops. the line if (isset($badges[$account->uid])) { needs an extra parenthesis, as shown here.

NancyDru’s picture

Status: Needs review » Fixed

Committed to 6.x-1.x-dev.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.