Skip to:

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#6601 closed defect (bug) (no action required)

BP calls update_meta_cache() 5997 times per page load

Reported by: wcvendors's profile wcvendors Owned by: r-a-y's profile r-a-y
Milestone: Priority: high
Severity: major Version: 2.3.2
Component: Messages Keywords:
Cc: stephen@…


When accessing the pages are loading slow, about 17 seconds instead of 2 seconds.

Query Monitor shows that "update_meta_cache()" from component BuddyPress is running 5997 times. That's about how many users we have on the entire site.

Query being called:
SELECT user_id, meta_key, meta_value
FROM wp_usermeta
WHERE user_id IN (1879)
ORDER BY umeta_id ASC

....and repeats 5997 times.

If I reload the webpage, it runs another 5997 times. If I load an individual message, no problems, standard 150 queries. It's just the /members/me/messages/ page.

Thoughts? Thanks!


Change History (8)

#1 @r-a-y
9 years ago

  • Owner set to r-a-y
  • Status changed from new to reviewing

Thanks for the report.

The query should only run once on a page, so it would be great to get further information.

Can you switch to the "Debug Bar" plugin instead of "Query Monitor"? Then, when you're on your "Messages" page, click on the "Debug" button from the WP admin bar and find the umeta call.

Next, copy the line that starts with require and paste it in this ticket so we can take a closer look.

You might need to set the following in wp-config.php:

define( 'SAVEQUERIES', true );

Last edited 9 years ago by r-a-y (previous) (diff)

#2 @netweb
9 years ago

  • Cc stephen@… added

#3 @boonebgorges
9 years ago

Just off the top of my head, but could it be that all users are being loaded into the at-mention script?

#4 @wcvendors
9 years ago

Debug Bar Results:

5,997 Queries

The big block of queries starts here:

SELECT user_id, meta_key, meta_value FROM wp_usermeta WHERE user_id IN (1699) ORDER BY umeta_id ASC

require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), include('/themes/superstore-child/buddypress.php'), the_content, apply_filters('the_content'), call_user_func_array, bp_replace_the_content, apply_filters('bp_replace_the_content'), call_user_func_array, BP_Members_Theme_Compat->single_dummy_content, bp_buffer_template_part, bp_get_template_part, bp_locate_template, load_template, require('/themes/superstore-child/buddypress/members/single/home.php'), bp_get_template_part, bp_locate_template, load_template, require('/themes/superstore-child/buddypress/members/single/messages.php'), bp_get_template_part, bp_locate_template, load_template, require('/themes/superstore-child/buddypress/members/single/messages/messages-loop.php'), bp_ajax_querystring, apply_filters('bp_ajax_querystring'), call_user_func_array, bpdev_exclude_users, bpdev_get_subscriber_user_ids, get_users, WP_User_Query->construct, WP_User_Query->query, WP_User->construct, WP_User->init, WP_User->for_blog, WP_User->_init_caps, get_user_meta, get_metadata, update_meta_cache

The only difference in the rest of the queries of course, is the user_id IN (XXXXXX)

#5 @boonebgorges
9 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from reviewing to closed

Thanks, wcvendors. The queries are originating from a BPDev plugin - is this BuddyDev? Find the plugin that contains bpdev_exclude_users() and try disabling it temporarily.

This is an issue that ought to be reported to the plugin author. At a glance, it looks like the plugin uses 'all_with_meta' in WP_User_Query (or maybe 'role'), and this is the source of your problem.

Since the bpdev plugin is not running through a BP utility (like BP_User_Query), I'm going to close this ticket. Please feel free to point the plugin author - I'm assuming it's Brajesh - to this ticket.

#6 @wcvendors
9 years ago

Thank you @boonebgorges

/* BuddyPress change members directory to only show vendors */
function bpdev_exclude_users($qs=false,$object=false){
    //list of users to exclude
    $excluded_user=join(',',bpdev_get_subscriber_user_ids());//comma separated ids of users whom you want to exclude
    if($object!='members')//hide for members only
        return $qs;
    //check if we are searching for friends list etc?, do not exclude in this case
        return $qs;
   return $qs;

function bpdev_get_subscriber_user_ids(){
    $subscribers= get_users( array( 'role' => 'customer' ) );
       foreach((array)$subscribers as $subscriber)
   return $users;

It appears this old legacy code was the issue in themes functions.php file. I've removed it and simply modified the template for the /members/ directory instead to show nothing instead, which is the true intent.

Appreciate your fast support, and apologies for thinking this was a general BuddyPress bug.


#7 @sbrajesh
9 years ago

Hi Boone, Ben,
It seems It was the code I had posted here.

Have updated it now to only get the ID's and not do any meta stuff etc. Also, There was no need to call 'bpdev_get_subscriber_user_ids' before checking for object type.

#8 @boonebgorges
9 years ago

Ben, Brajesh - Many thanks to both of you for reporting back! Glad to see that this is resolved.

Note: See TracTickets for help on using tickets.