Skip to:
Content

BuddyPress.org

Changeset 7905


Ignore:
Timestamp:
02/17/2014 01:02:25 AM (13 years ago)
Author:
boonebgorges
Message:

Introduce 'update_meta_cache' param to bp_has_activities() stack

See #5398

Location:
trunk
Files:
4 edited

Legend:

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

    r7901 r7905  
    249249         *                             Default: false.
    250250         *     @type string $spam Spam status. Default: 'ham_only'.
     251         *     @type bool $update_meta_cache Whether to pre-fetch metadata for
     252         *           queried activity items. Default: true.
    251253         * }
    252254         * @return array The array returned has two keys:
     
    431433                }
    432434
    433                 if ( !empty( $activity_ids ) ) {
     435                if ( ! empty( $activity_ids ) && $update_meta_cache ) {
    434436                        bp_activity_update_meta_cache( $activity_ids );
    435437                }
  • trunk/bp-activity/bp-activity-functions.php

    r7885 r7905  
    911911                'in'               => false,        // Comma-separated list or array of activity IDs to which you want to limit the query
    912912                'spam'             => 'ham_only',   // 'ham_only' (default), 'spam_only' or 'all'.
     913                'update_meta_cache' => true,
    913914
    914915                /**
     
    940941                                'display_comments' => $display_comments,
    941942                                'show_hidden'      => $show_hidden,
    942                                 'spam'             => $spam
     943                                'spam'             => $spam,
     944                                'update_meta_cache' => $update_meta_cache,
    943945                        );
    944946                        $activity = BP_Activity_Activity::get( $args );
     
    981983 *     except for the following:
    982984 *     @type string|int|array Single activity ID, comma-separated list of IDs,
    983  *                            or array of IDs.
     985 *           or array of IDs.
    984986 * }
    985987 * @return array $activity See BP_Activity_Activity::get() for description.
     
    995997                'sort'             => 'DESC',      // sort ASC or DESC
    996998                'spam'             => 'ham_only',  // Retrieve items marked as spam
     999                'update_meta_cache' => true,
    9971000        );
    9981001        $r = wp_parse_args( $args, $defaults );
     
    10071010                'show_hidden'      => $show_hidden,
    10081011                'in'               => $activity_ids,
    1009                 'spam'             => $spam
     1012                'spam'             => $spam,
     1013                'update_meta_cache' => $update_meta_cache,
    10101014        );
    10111015        return apply_filters( 'bp_activity_get_specific', BP_Activity_Activity::get( $get_args ), $args, $get_args );
  • trunk/bp-activity/bp-activity-template.php

    r7899 r7905  
    174174                        'show_hidden'      => false,
    175175                        'spam'             => 'ham_only',
     176                        'update_meta_cache' => true,
    176177                );
    177178                $r = wp_parse_args( $args, $defaults );
     
    189190                // Fetch specific activity items based on ID's
    190191                if ( !empty( $include ) )
    191                         $this->activities = bp_activity_get_specific( array( 'activity_ids' => explode( ',', $include ), 'max' => $max, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'sort' => $sort, 'display_comments' => $display_comments, 'show_hidden' => $show_hidden, 'spam' => $spam ) );
     192                        $this->activities = bp_activity_get_specific( array( 'activity_ids' => explode( ',', $include ), 'max' => $max, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'sort' => $sort, 'display_comments' => $display_comments, 'show_hidden' => $show_hidden, 'spam' => $spam, 'update_meta_cache' => $update_meta_cache, ) );
    192193
    193194                // Fetch all activity items
    194195                else
    195                         $this->activities = bp_activity_get( array( 'display_comments' => $display_comments, 'max' => $max, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'sort' => $sort, 'search_terms' => $search_terms, 'meta_query' => $meta_query, 'filter' => $filter, 'show_hidden' => $show_hidden, 'exclude' => $exclude, 'in' => $in, 'spam' => $spam ) );
     196                        $this->activities = bp_activity_get( array( 'display_comments' => $display_comments, 'max' => $max, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'sort' => $sort, 'search_terms' => $search_terms, 'meta_query' => $meta_query, 'filter' => $filter, 'show_hidden' => $show_hidden, 'exclude' => $exclude, 'in' => $in, 'spam' => $spam, 'update_meta_cache' => $update_meta_cache, ) );
    196197
    197198                if ( !$max || $max >= (int) $this->activities['total'] )
     
    449450 *     @type string|bool $spam Spam status. 'ham_only', 'spam_only', or false
    450451 *           to show all activity regardless of spam status. Default: 'ham_only'.
     452 *     @type bool $populate_extras Whether to pre-fetch the activity metadata
     453 *           for the queried items. Default: true.
    451454 * }
    452455 * @return bool Returns true when activities are found, otherwise false.
     
    520523
    521524                // Searching
    522                 'search_terms'     => false         // specify terms to search on
     525                'search_terms'     => false,        // specify terms to search on
     526                'update_meta_cache' => true,
    523527        );
    524528
     
    627631                'display_comments' => $display_comments,
    628632                'show_hidden'      => $show_hidden,
    629                 'spam'             => $spam
     633                'spam'             => $spam,
     634                'update_meta_cache' => $update_meta_cache,
    630635        );
    631636
  • trunk/tests/testcases/activity/template.php

    r7574 r7905  
    254254
    255255        }
     256
     257        /**
     258         * @group bp_has_activities
     259         * @group cache
     260         */
     261        public function test_bp_has_activities_with_update_meta_cache_false() {
     262                $now = time();
     263                $a1 = $this->factory->activity->create( array(
     264                        'content' => 'Life Rules',
     265                        'recorded_time' => date( 'Y-m-d H:i:s', $now ),
     266                ) );
     267                $a2 = $this->factory->activity->create( array(
     268                        'content' => 'Life Drools',
     269                        'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     270                ) );
     271
     272                bp_activity_add_meta( $a1, 'foo', 'bar' );
     273                bp_activity_add_meta( $a2, 'foo1', 'bar2' );
     274
     275                // prime
     276                bp_has_activities( array(
     277                        'update_meta_cache' => false,
     278                ) );
     279
     280                $this->assertFalse( wp_cache_get( $a1, 'activity_meta' ) );
     281                $this->assertFalse( wp_cache_get( $a2, 'activity_meta' ) );
     282        }
     283
     284        /**
     285         * @group bp_has_activities
     286         * @group cache
     287         */
     288        public function test_bp_has_activities_with_update_meta_cache_true() {
     289                $now = time();
     290                $a1 = $this->factory->activity->create( array(
     291                        'content' => 'Life Rules',
     292                        'recorded_time' => date( 'Y-m-d H:i:s', $now ),
     293                ) );
     294                $a2 = $this->factory->activity->create( array(
     295                        'content' => 'Life Drools',
     296                        'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     297                ) );
     298
     299                bp_activity_add_meta( $a1, 'foo', 'bar' );
     300                bp_activity_add_meta( $a2, 'foo1', 'bar2' );
     301
     302                // prime
     303                bp_has_activities( array(
     304                        'update_meta_cache' => true,
     305                ) );
     306
     307                $this->assertNotEmpty( wp_cache_get( $a1, 'activity_meta' ) );
     308                $this->assertNotEmpty( wp_cache_get( $a2, 'activity_meta' ) );
     309        }
    256310}
Note: See TracChangeset for help on using the changeset viewer.