#6601 closed defect (bug) (no action required)
BP calls update_meta_cache() 5997 times per page load
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | Priority: | high | |
Severity: | major | Version: | 2.3.2 |
Component: | Messages | Keywords: | |
Cc: | stephen@… |
Description
When accessing mydomain.com/members/me/messages/ 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!
Ben
Change History (8)
#3
@
10 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
@
10 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
@
10 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
@
10 years ago
Thank you @boonebgorges
/* BuddyPress change members directory to only show vendors */ add_action('bp_ajax_querystring','bpdev_exclude_users',20,2); 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; $args=wp_parse_args($qs); //check if we are searching for friends list etc?, do not exclude in this case if(!empty($args['user_id'])) return $qs; if(!empty($args['exclude'])) $args['exclude']=$args['exclude'].','.$excluded_user; else $args['exclude']=$excluded_user; $qs=build_query($args); return $qs; } function bpdev_get_subscriber_user_ids(){ $users=array(); $subscribers= get_users( array( 'role' => 'customer' ) ); if(!empty($subscribers)){ foreach((array)$subscribers as $subscriber) $users[]=$subscriber->ID; } 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.
Ben
#7
@
10 years ago
Hi Boone, Ben,
It seems It was the code I had posted here.
https://gist.github.com/sbrajesh/2142009
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.
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 );