[buddypress-trac] [BuddyPress Trac] #7382: groups_promote_member() shouldn't attempt to fetch `BP_Core_User` object
buddypress-trac
noreply at wordpress.org
Thu Dec 8 08:24:26 UTC 2016
#7382: groups_promote_member() shouldn't attempt to fetch `BP_Core_User` object
-------------------------+-----------------------
Reporter: r-a-y | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: 2.8
Component: Groups | Version: 1.0
Severity: normal | Keywords: has-patch
-------------------------+-----------------------
When a member is being promoted and if the XProfile and Friends components
are active, four DB queries are being run for no reason.
Here's a captured DB query log when a member is being promoted:
{{{
[18] => Array
(
[0] => SELECT * FROM wp_bp_groups_members WHERE user_id = 7670
AND group_id = 1218
[1] => 0.0004730224609375
[2] => require('wp-blog-header.php'), require_once('wp-
includes/template-loader.php'), do_action('template_redirect'),
call_user_func_array, bp_template_redirect,
do_action('bp_template_redirect'), call_user_func_array, bp_screens,
do_action('bp_screens'), call_user_func_array,
groups_screen_group_admin_manage_members, groups_promote_member,
BP_Groups_Member->__construct, BP_Groups_Member->populate
)
[19] => Array
(
[0] => SELECT DISTINCT g.id FROM wp_bp_xprofile_groups g INNER
JOIN wp_bp_xprofile_fields f ON g.id = f.group_id ORDER BY g.group_order
ASC
[1] => 0.00040388107299805
[2] => require('wp-blog-header.php'), require_once('wp-
includes/template-loader.php'), do_action('template_redirect'),
call_user_func_array, bp_template_redirect,
do_action('bp_template_redirect'), call_user_func_array, bp_screens,
do_action('bp_screens'), call_user_func_array,
groups_screen_group_admin_manage_members, groups_promote_member,
BP_Groups_Member->__construct, BP_Groups_Member->populate,
BP_Core_User->__construct, BP_Core_User->populate,
BP_Core_User->get_profile_data, BP_XProfile_ProfileData::get_all_for_user,
bp_xprofile_get_groups, BP_XProfile_Group::get
)
[20] => Array
(
[0] => SELECT id, initiator_user_id, is_confirmed FROM
wp_bp_friends WHERE (initiator_user_id = 7670 AND friend_user_id = 6178)
OR (initiator_user_id = 6178 AND friend_user_id = 7670)
[1] => 0.00040698051452637
[2] => require('wp-blog-header.php'), require_once('wp-
includes/template-loader.php'), do_action('template_redirect'),
call_user_func_array, bp_template_redirect,
do_action('bp_template_redirect'), call_user_func_array, bp_screens,
do_action('bp_screens'), call_user_func_array,
groups_screen_group_admin_manage_members, groups_promote_member,
BP_Groups_Member->__construct, BP_Groups_Member->populate,
BP_Core_User->__construct, BP_Core_User->populate,
BP_Core_User->get_profile_data, BP_XProfile_ProfileData::get_all_for_user,
bp_xprofile_get_groups, BP_XProfile_Group::get,
bp_xprofile_get_hidden_fields_for_user,
bp_xprofile_get_hidden_field_types_for_user, friends_check_friendship,
BP_Friends_Friendship::check_is_friend
)
[21] => Array
(
[0] => SELECT id FROM wp_bp_xprofile_fields WHERE group_id IN
( 1 ) AND parent_id = 0 ORDER BY field_order
[1] => 0.00043106079101562
[2] => require('wp-blog-header.php'), require_once('wp-
includes/template-loader.php'), do_action('template_redirect'),
call_user_func_array, bp_template_redirect,
do_action('bp_template_redirect'), call_user_func_array, bp_screens,
do_action('bp_screens'), call_user_func_array,
groups_screen_group_admin_manage_members, groups_promote_member,
BP_Groups_Member->__construct, BP_Groups_Member->populate,
BP_Core_User->__construct, BP_Core_User->populate,
BP_Core_User->get_profile_data, BP_XProfile_ProfileData::get_all_for_user,
bp_xprofile_get_groups, BP_XProfile_Group::get
)
[22] => Array
(
[0] => SELECT object_id, object_type, meta_key, meta_value
FROM wp_bp_xprofile_meta WHERE ( object_type = '0' AND object_id IN (0) )
OR ( object_type = '1' AND object_id IN (0) ) OR ( object_type = '2' AND
object_id IN (0) ) OR ( object_type = 'group' AND object_id IN (1) ) OR (
object_type = 'data' AND object_id IN (51126,0,51127) )
[1] => 0.00044393539428711
[2] => require('wp-blog-header.php'), require_once('wp-
includes/template-loader.php'), do_action('template_redirect'),
call_user_func_array, bp_template_redirect,
do_action('bp_template_redirect'), call_user_func_array, bp_screens,
do_action('bp_screens'), call_user_func_array,
groups_screen_group_admin_manage_members, groups_promote_member,
BP_Groups_Member->__construct, BP_Groups_Member->populate,
BP_Core_User->__construct, BP_Core_User->populate,
BP_Core_User->get_profile_data, BP_XProfile_ProfileData::get_all_for_user,
bp_xprofile_get_groups, BP_XProfile_Group::get,
bp_xprofile_update_meta_cache
)
[23] => Array
(
[0] => UPDATE wp_bp_groups_members SET inviter_id = 0,
is_admin = 1, is_mod = 0, is_banned = 0, user_title = 'Group Admin',
date_modified = '2016-11-15 20:43:13', is_confirmed = 1, comments = '',
invite_sent = 0 WHERE id = 33812
[1] => 0.00058197975158691
[2] => require('wp-blog-header.php'), require_once('wp-
includes/template-loader.php'), do_action('template_redirect'),
call_user_func_array, bp_template_redirect,
do_action('bp_template_redirect'), call_user_func_array, bp_screens,
do_action('bp_screens'), call_user_func_array,
groups_screen_group_admin_manage_members, groups_promote_member,
BP_Groups_Member->promote, BP_Groups_Member->save
}}}
The following patch makes it so we can remove these four unnecessary DB
queries by adding some options to disable populating the user object in
the `BP_Groups_Member::populate()` method.
Let me know if you have any questions about the technique.
--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/7382>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac
More information about the buddypress-trac
mailing list