Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/13/2021 03:16:36 PM (3 years ago)
Author:
imath
Message:

Add a new param to bp_activity_get() to only get the number of items

Using the count_total_only parameter with bp_activity_get() will only run the query to count the number of activity items. Using this new parameter into the Activity WP Admin Screen improves the performance of the query to get the total number of activities.

Props oztaser

Fixes #8591

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/activity/functions.php

    r13128 r13146  
    19751975        $this->assertSame( $latest_update, bp_get_user_meta( $u1, 'bp_latest_update', true ) );
    19761976    }
     1977
     1978    /**
     1979     * @ticket BP8591
     1980     */
     1981    public function test_activity_admin_screen_count_activities() {
     1982        $u1 = self::factory()->user->create();
     1983        $a1 = self::factory()->activity->create_many(
     1984            5,
     1985            array(
     1986                'user_id'   => $u1,
     1987                'component' => 'activity',
     1988                'type'      => 'activity_update',
     1989            )
     1990        );
     1991        bp_update_user_last_activity( $u1, date( 'Y-m-d H:i:s', bp_core_current_time( true, 'timestamp' ) ) );
     1992
     1993        $count_activities = bp_activity_get(
     1994            array(
     1995                'show_hidden'      => true,
     1996                'count_total_only' => true,
     1997            )
     1998        );
     1999
     2000        $this->assertTrue( 5 === (int) $count_activities['total'] );
     2001    }
    19772002}
Note: See TracChangeset for help on using the changeset viewer.