Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/31/2014 09:27:11 PM (11 years ago)
Author:
boonebgorges
Message:

When prefetching group data for an activity loop, avoid the query when there's nothing to fetch

When there are no uncached_ids, don't attempt to query. There's nothing to get,
and it will result in an invalidly formatted SQL query.

Fixes #5503

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/testcases/groups/cache.php

    r7956 r8224  
    102102    }
    103103
     104    /**
     105     * @group bp_groups_prefetch_activity_object_data
     106     */
     107    public function test_bp_groups_prefetch_activity_object_data_all_cached() {
     108        $g = $this->factory->group->create();
     109
     110        // Prime cache
     111        groups_get_group( array( 'group_id' => $g ) );
     112
     113        // fake an activity
     114        $a = new stdClass;
     115        $a->component = buddypress()->groups->id;
     116        $a->item_id = $g;
     117        $activities = array(
     118            $a,
     119        );
     120
     121        bp_groups_prefetch_activity_object_data( $activities );
     122
     123        // This assertion is not really necessary - just checks to see
     124        // whether a fatal error has occurred above
     125        $this->assertNotEmpty( wp_cache_get( $g, 'bp_groups' ) );
     126    }
     127
     128    /**
     129     * @group bp_groups_prefetch_activity_object_data
     130     */
     131    public function test_bp_groups_prefetch_activity_object_data_some_cached() {
     132        $g1 = $this->factory->group->create();
     133        $g2 = $this->factory->group->create();
     134
     135        // Prime cache
     136        groups_get_group( array( 'group_id' => $g1 ) );
     137
     138        // fake activities
     139        $a1 = new stdClass;
     140        $a1->component = buddypress()->groups->id;
     141        $a1->item_id = $g1;
     142
     143        $a2 = new stdClass;
     144        $a2->component = buddypress()->groups->id;
     145        $a2->item_id = $g2;
     146
     147        $activities = array(
     148            $a1,
     149            $a2,
     150        );
     151
     152        bp_groups_prefetch_activity_object_data( $activities );
     153
     154        $this->assertNotEmpty( wp_cache_get( $g1, 'bp_groups' ) );
     155        $this->assertNotEmpty( wp_cache_get( $g2, 'bp_groups' ) );
     156    }
    104157}
Note: See TracChangeset for help on using the changeset viewer.