Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
10/07/2015 02:30:31 PM (9 years ago)
Author:
boonebgorges
Message:

Introduce cache support for xprofile fields.

xprofile_get_field() will now look in the cache before returning a
BP_XProfile_Field object (via the new BP_XProfile_Field::get_instance()),
and will populate the cache if necessary. It's strongly recommended to use
xprofile_get_field() when fetching individual existing fields, instead of
creating new BP_XProfile_Field objects directly.

BP_XProfile_Group::get() now leverages the field cache too. Instead of a
SELECT * query, it fetches a list of matching field IDs SELECT id, and
populates the full field objects from the cache, if available. The fields
property of BP_XProfile_Group objects is now an array of BP_XProfile_Field
objects, not stdClass. See #6358.

Props boonebgorges, r-a-y.
See #6638.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/xprofile/cache.php

    r10004 r10198  
    145145        $this->assertFalse( wp_cache_get( $d->id, 'xprofile_data_meta' ) );
    146146    }
     147
     148    /**
     149     * @ticket BP6638
     150     */
     151    public function test_field_cache_should_be_invalidated_on_save() {
     152        $g = $this->factory->xprofile_group->create();
     153        $f = $this->factory->xprofile_field->create( array(
     154            'field_group_id' => $g,
     155            'name' => 'Foo',
     156        ) );
     157
     158        $field = xprofile_get_field( $f );
     159        $this->assertSame( 'Foo', $field->name );
     160
     161        $field->name = 'Bar';
     162        $this->assertNotEmpty( $field->save() );
     163
     164        $field_2 = xprofile_get_field( $f );
     165        $this->assertSame( 'Bar', $field_2->name );
     166    }
    147167}
Note: See TracChangeset for help on using the changeset viewer.