Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/17/2014 07:42:03 PM (11 years ago)
Author:
boonebgorges
Message:

Introduce metadata pre-fetching for xprofile objects

XProfile objects (groups, fields, and data) are generally fetched in a nested
way, as within the context of a bp_has_profile() loop. Thus, it makes sense to
pre-fetch xprofile metadata within a bp_has_profile() loop in a nested way as
well. This changeset introduces bp_xprofile_update_meta_cache(), which is able
to fetch all uncached metadata for nested meta types with a single database
query.

This changeset also introduces an 'update_meta_cache' parameter to the
bp_has_profile() stack. This param allows developers to disable the pre-
fetching introduced here. Defaults to true.

See #5398

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-xprofile/bp-xprofile-template.php

    r7888 r7914  
    2525    var $user_id;
    2626
    27     function __construct( $user_id, $profile_group_id, $hide_empty_groups = false, $fetch_fields = false, $fetch_field_data = false, $exclude_groups = false, $exclude_fields = false, $hide_empty_fields = false, $fetch_visibility_level = false ) {
     27    function __construct( $user_id, $profile_group_id, $hide_empty_groups = false, $fetch_fields = false, $fetch_field_data = false, $exclude_groups = false, $exclude_fields = false, $hide_empty_fields = false, $fetch_visibility_level = false, $update_meta_cache = true ) {
    2828        $this->groups = BP_XProfile_Group::get( array(
    2929            'profile_group_id'    => $profile_group_id,
     
    3535            'fetch_visibility_level' => $fetch_visibility_level,
    3636            'exclude_groups'      => $exclude_groups,
    37             'exclude_fields'      => $exclude_fields
     37            'exclude_fields'      => $exclude_fields,
     38            'update_meta_cache'   => $update_meta_cache,
    3839        ) );
    3940
     
    175176        'fetch_visibility_level' => $fetch_visibility_level_default,
    176177        'exclude_groups'      => false, // Comma-separated list of profile field group IDs to exclude
    177         'exclude_fields'      => false  // Comma-separated list of profile field IDs to exclude
     178        'exclude_fields'      => false,  // Comma-separated list of profile field IDs to exclude
     179        'update_meta_cache'   => true,
    178180    );
    179181
     
    181183    extract( $r, EXTR_SKIP );
    182184
    183     $profile_template = new BP_XProfile_Data_Template( $user_id, $profile_group_id, $hide_empty_groups, $fetch_fields, $fetch_field_data, $exclude_groups, $exclude_fields, $hide_empty_fields, $fetch_visibility_level );
     185    $profile_template = new BP_XProfile_Data_Template( $user_id, $profile_group_id, $hide_empty_groups, $fetch_fields, $fetch_field_data, $exclude_groups, $exclude_fields, $hide_empty_fields, $fetch_visibility_level, $update_meta_cache );
    184186    return apply_filters( 'bp_has_profile', $profile_template->has_groups(), $profile_template );
    185187}
Note: See TracChangeset for help on using the changeset viewer.