Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/09/2016 03:30:07 PM (10 years ago)
Author:
boonebgorges
Message:

Cache the results of group ID and count queries.

Query results are cached using an incrementor, and are invalidated in
bulk whenever a group is created, updated, or deleted, or when
groupmeta is modified.

See #5451.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/groups/class-bp-groups-group.php

    r11071 r11072  
    508508        }
    509509
     510        /**
     511         * @group cache
     512         * @ticket BP5451
     513         * @ticket BP6643
     514         */
     515        public function test_get_queries_should_be_cached() {
     516                global $wpdb;
     517
     518                $g = $this->factory->group->create();
     519
     520                $found1 = BP_Groups_Group::get();
     521
     522                $num_queries = $wpdb->num_queries;
     523
     524                $found2 = BP_Groups_Group::get();
     525
     526                $this->assertEqualSets( $found1, $found2 );
     527                $this->assertSame( $num_queries, $wpdb->num_queries );
     528        }
     529
     530        /**
     531         * @group cache
     532         * @ticket BP5451
     533         * @ticket BP6643
     534         */
     535        public function test_get_query_caches_should_be_busted_by_groupmeta_update() {
     536                global $wpdb;
     537
     538                $groups = $this->factory->group->create_many( 2 );
     539                groups_update_groupmeta( $groups[0], 'foo', 'bar' );
     540                groups_update_groupmeta( $groups[1], 'foo', 'bar' );
     541
     542                $found1 = BP_Groups_Group::get( array(
     543                        'meta_query' => array(
     544                                array(
     545                                        'key' => 'foo',
     546                                        'value' => 'bar',
     547                                ),
     548                        ),
     549                ) );
     550
     551                $this->assertEqualSets( array( $groups[0], $groups[1] ), wp_list_pluck( $found1['groups'], 'id' ) );
     552
     553                groups_update_groupmeta( $groups[1], 'foo', 'baz' );
     554
     555                $found2 = BP_Groups_Group::get( array(
     556                        'meta_query' => array(
     557                                array(
     558                                        'key' => 'foo',
     559                                        'value' => 'bar',
     560                                ),
     561                        ),
     562                ) );
     563
     564                $this->assertEqualSets( array( $groups[0] ), wp_list_pluck( $found2['groups'], 'id' ) );
     565        }
     566
     567        /**
     568         * @group cache
     569         * @ticket BP5451
     570         * @ticket BP6643
     571         */
     572        public function test_get_query_caches_should_be_busted_by_group_save() {
     573                global $wpdb;
     574
     575                $groups = $this->factory->group->create_many( 2 );
     576                groups_update_groupmeta( $groups[0], 'foo', 'bar' );
     577                groups_update_groupmeta( $groups[1], 'foo', 'bar' );
     578
     579                $found1 = BP_Groups_Group::get( array(
     580                        'search_terms' => 'Foo',
     581                ) );
     582
     583                $this->assertEmpty( $found1['groups'] );
     584
     585                $group0 = groups_get_group( array( 'group_id' => $groups[0] ) );
     586                $group0->name = 'Foo';
     587                $group0->save();
     588
     589                $found2 = BP_Groups_Group::get( array(
     590                        'search_terms' => 'Foo',
     591                ) );
     592
     593                $this->assertEqualSets( array( $groups[0] ), wp_list_pluck( $found2['groups'], 'id' ) );
     594        }
     595
     596        /**
     597         * @group cache
     598         * @ticket BP5451
     599         * @ticket BP6643
     600         */
     601        public function test_get_query_caches_should_be_busted_by_group_delete() {
     602                global $wpdb;
     603
     604                $groups = $this->factory->group->create_many( 2 );
     605
     606                $found1 = BP_Groups_Group::get();
     607
     608                $this->assertEqualSets( $groups, wp_list_pluck( $found1['groups'], 'id' ) );
     609
     610                $group0 = groups_get_group( array( 'group_id' => $groups[0] ) );
     611                $group0->delete();
     612
     613                $found2 = BP_Groups_Group::get();
     614
     615                $this->assertEqualSets( array( $groups[1] ), wp_list_pluck( $found2['groups'], 'id' ) );
     616        }
     617
    510618        /** convert_type_to_order_orderby() **********************************/
    511619
Note: See TracChangeset for help on using the changeset viewer.