Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/13/2016 04:05:07 AM (10 years ago)
Author:
boonebgorges
Message:

Groups: Improve query efficiency for 'admins' and 'mods' properties of group objects.

Previously, the 'admins' and 'mods' property of BP_Groups_Group
objects were only populated when setting the 'populate_extras' flag.
Even then, the query used to populate these properties was uncached,
and required a join against a global table.

This changeset reworks the way that the 'admins' and 'mods' properties
are accessed and set. The properties are now marked protected, and
are accessible by magic __get(). When requested, the cache for the
both properties is set by a single pair of queries: one to fetch
membership data from the BP table, and one to get user objects from
WordPress. The BP table query is cached, and neither query takes place
if the property is never accessed.

This moves us a step closer to eliminating the populate_extras flag
on BP_Groups_Group objects.

See #5451.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/bp-groups-cache.php

    r11075 r11087  
    185185
    186186/**
    187  * Clear group administrator cache.
     187 * Clear group administrator and moderator cache.
    188188 *
    189189 * @since 2.1.0
     
    193193function groups_clear_group_administrator_cache( $group_id ) {
    194194    wp_cache_delete( $group_id, 'bp_group_admins' );
     195    wp_cache_delete( $group_id, 'bp_group_mods' );
    195196}
    196197add_action( 'groups_promote_member', 'groups_clear_group_administrator_cache' );
     
    199200
    200201/**
    201  * Clear group administrator cache when a group member is saved.
    202  *
    203  * This accounts for situations where group administrators are added manually
     202 * Clear group administrator and moderator cache when a group member is saved.
     203 *
     204 * This accounts for situations where group admins or mods are added manually
    204205 * using {@link BP_Groups_Member::save()}.  Usually via a plugin.
    205206 *
Note: See TracChangeset for help on using the changeset viewer.