Skip to:
Content

BuddyPress.org

Changeset 7903


Ignore:
Timestamp:
02/17/2014 12:35:26 AM (8 years ago)
Author:
boonebgorges
Message:

Don't prime groupmeta cache in BP_Groups_Group::construct()

groups_get_groupmeta() now uses the core API functions. get_metadata() works by
priming the cache with *all* object metadata when requesting any piece of
metadata for that object. This means that, instead of pre-fetching groupmeta
when instantiating BP_Groups_Group, we wait until it happens in get_metadata().
At best, this can help us to avoid pre-fetching a meta cache that will not be
used.

See #5398

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-groups/bp-groups-classes.php

    r7898 r7903  
    176176
    177177        if ( $group = $wpdb->get_row( $wpdb->prepare( "SELECT g.* FROM {$bp->groups->table_name} g WHERE g.id = %d", $this->id ) ) ) {
    178             if ( ! empty( $this->args['update_meta_cache'] ) ) {
    179                 bp_groups_update_meta_cache( $this->id );
    180             }
    181 
    182178            $this->id                 = $group->id;
    183179            $this->creator_id         = $group->creator_id;
  • trunk/bp-groups/bp-groups-functions.php

    r7898 r7903  
    4545        'load_users'        => false,
    4646        'populate_extras'   => true,
    47         'update_meta_cache' => true,
    4847    );
    4948
     
    5655        $group_args = array(
    5756            'populate_extras'   => $populate_extras,
    58             'update_meta_cache' => $update_meta_cache,
    5957        );
    6058
  • trunk/tests/testcases/groups/functions.php

    r7887 r7903  
    438438    /**
    439439     * @group groupmeta
     440     * @group groups_get_groupmeta
     441     * @group cache
     442     */
     443    public function test_groups_get_groupmeta_cache_all_on_get() {
     444        $g = $this->factory->group->create();
     445        groups_add_groupmeta( $g, 'foo', 'bar' );
     446        groups_add_groupmeta( $g, 'foo1', 'baz' );
     447        $this->assertFalse( wp_cache_get( $g, 'group_meta' ) );
     448
     449        // A single query should prime the whole meta cache
     450        groups_get_groupmeta( $g, 'foo' );
     451
     452        $c = wp_cache_get( $g, 'group_meta' );
     453        $this->assertNotEmpty( $c['foo1'] );
     454    }
     455
     456    /**
     457     * @group groupmeta
    440458     */
    441459    public function test_groups_delete_groupmeta_non_numeric_id() {
Note: See TracChangeset for help on using the changeset viewer.