Changeset 13146
- Timestamp:
- 11/13/2021 03:16:36 PM (3 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-activity/bp-activity-functions.php
r13135 r13146 1784 1784 'sort' => 'DESC', // sort ASC or DESC. 1785 1785 'display_comments' => false, // False for no comments. 'stream' for within stream display, 'threaded' for below each activity item. 1786 1787 1786 'search_terms' => false, // Pass search terms as a string. 1788 1787 'meta_query' => false, // Filter by activity meta. See WP_Meta_Query for format. … … 1791 1790 'show_hidden' => false, // Show activity items that are hidden site-wide? 1792 1791 'exclude' => false, // Comma-separated list of activity IDs to exclude. 1793 'in' => false, // Comma-separated list or array of activity IDs to which you. 1794 // want to limit the query. 1792 'in' => false, // Comma-separated list or array of activity IDs to which you want to limit the query. 1795 1793 'spam' => 'ham_only', // 'ham_only' (default), 'spam_only' or 'all'. 1796 1794 'update_meta_cache' => true, 1797 1795 'count_total' => false, 1796 'count_total_only' => false, 1798 1797 'scope' => false, 1799 1798 … … 1813 1812 ); 1814 1813 1815 $activity = BP_Activity_Activity::get( array( 1816 'page' => $r['page'], 1817 'per_page' => $r['per_page'], 1818 'max' => $r['max'], 1819 'sort' => $r['sort'], 1820 'search_terms' => $r['search_terms'], 1821 'meta_query' => $r['meta_query'], 1822 'date_query' => $r['date_query'], 1823 'filter_query' => $r['filter_query'], 1824 'filter' => $r['filter'], 1825 'scope' => $r['scope'], 1826 'display_comments' => $r['display_comments'], 1827 'show_hidden' => $r['show_hidden'], 1828 'exclude' => $r['exclude'], 1829 'in' => $r['in'], 1830 'spam' => $r['spam'], 1831 'update_meta_cache' => $r['update_meta_cache'], 1832 'count_total' => $r['count_total'], 1833 'fields' => $r['fields'], 1834 ) ); 1814 $activity = BP_Activity_Activity::get( 1815 array( 1816 'page' => $r['page'], 1817 'per_page' => $r['per_page'], 1818 'max' => $r['max'], 1819 'sort' => $r['sort'], 1820 'search_terms' => $r['search_terms'], 1821 'meta_query' => $r['meta_query'], 1822 'date_query' => $r['date_query'], 1823 'filter_query' => $r['filter_query'], 1824 'filter' => $r['filter'], 1825 'scope' => $r['scope'], 1826 'display_comments' => $r['display_comments'], 1827 'show_hidden' => $r['show_hidden'], 1828 'exclude' => $r['exclude'], 1829 'in' => $r['in'], 1830 'spam' => $r['spam'], 1831 'update_meta_cache' => $r['update_meta_cache'], 1832 'count_total' => $r['count_total'], 1833 'count_total_only' => $r['count_total_only'], 1834 'fields' => $r['fields'], 1835 ) 1836 ); 1835 1837 1836 1838 /** -
trunk/src/bp-activity/classes/class-bp-activity-activity.php
r13108 r13146 342 342 * @since 2.4.0 Introduced the `$fields` parameter. 343 343 * @since 2.9.0 Introduced the `$order_by` parameter. 344 * @since 10.0.0 Introduced the `$count_total_only` parameter. 344 345 * 345 346 * @see BP_Activity_Activity::get_filter_sql() for a description of the … … 373 374 * @type string|bool $count_total If true, an additional DB query is run to count the total activity items 374 375 * for the query. Default: false. 376 * @type bool $count_total_only If true, only the DB query to count the total activity items is run. 377 * Default: false. 375 378 * } 376 379 * @return array The array returned has two keys: … … 436 439 'update_meta_cache' => true, // Whether or not to update meta cache. 437 440 'count_total' => false, // Whether or not to use count_total. 441 'count_total_only' => false, // Whether to only get the total count. 438 442 ) 439 443 ); … … 630 634 ); 631 635 636 // Init the activity list. 637 $activities = array(); 638 $only_get_count = (bool) $r['count_total_only']; 639 632 640 /** 633 641 * Filters if BuddyPress should use legacy query structure over current structure for version 2.0+. … … 641 649 * @param array $r Parsed arguments passed into method. 642 650 */ 643 if ( apply_filters( 'bp_use_legacy_activity_query', false, __METHOD__, $r ) ) {651 if ( ! $only_get_count && apply_filters( 'bp_use_legacy_activity_query', false, __METHOD__, $r ) ) { 644 652 645 653 // Legacy queries joined against the user table. … … 693 701 } 694 702 695 } else {703 } elseif ( ! $only_get_count ) { 696 704 // Query first for activity IDs. 697 705 $activity_ids_sql = "{$select_sql} {$from_sql} {$join_sql} {$where_sql} ORDER BY {$order_by} {$sort}, a.id {$sort}"; … … 746 754 } 747 755 748 if ( 'ids' !== $r['fields'] ) {756 if ( $activities && 'ids' !== $r['fields'] ) { 749 757 // Get the fullnames of users so we don't have to query in the loop. 750 758 $activities = self::append_user_fullnames( $activities ); … … 773 781 $retval['activities'] = $activities; 774 782 775 // If $max is set, only return up to the max results. 776 if ( ! empty( $r['count_total'] ) ) { 777 783 // Only query the count total if requested. 784 if ( ! empty( $r['count_total'] ) || $only_get_count ) { 778 785 /** 779 786 * Filters the total activities MySQL statement. … … 786 793 */ 787 794 $total_activities_sql = apply_filters( 'bp_activity_total_activities_sql', "SELECT count(DISTINCT a.id) FROM {$bp->activity->table_name} a {$join_sql} {$where_sql}", $where_sql, $sort ); 795 796 /* 797 * Queries that include 'last_activity' are cached separately, 798 * since they are generally much less long-lived. 799 */ 800 if ( preg_match( '/a\.type NOT IN \([^\)]*\'last_activity\'[^\)]*\)/', $total_activities_sql ) ) { 801 $cache_group = 'bp_activity'; 802 } else { 803 $cache_group = 'bp_activity_with_last_activity'; 804 } 805 788 806 $cached = bp_core_get_incremented_cache( $total_activities_sql, $cache_group ); 789 807 if ( false === $cached ) { … … 794 812 } 795 813 796 if ( !empty( $r['max'] ) ) { 814 // If $max is set, only return up to the max results. 815 if ( ! empty( $r['max'] ) ) { 797 816 if ( (int) $total_activities > (int) $r['max'] ) { 798 817 $total_activities = $r['max']; -
trunk/src/bp-activity/classes/class-bp-activity-list-table.php
r12659 r13146 157 157 'show_hidden' => true, 158 158 'spam' => 'spam_only', 159 'count_total ' => 'count_query',159 'count_total_only' => true, 160 160 ) ); 161 161 $this->spam_count = $spams['total']; … … 215 215 $count_activities = bp_activity_get( 216 216 array( 217 'fields' => 'ids',218 'show_hidden' => true,219 'count_total ' => 'count_query',217 'fields' => 'ids', 218 'show_hidden' => true, 219 'count_total_only' => true, 220 220 ) 221 221 ); -
trunk/tests/phpunit/testcases/activity/functions.php
r13128 r13146 1975 1975 $this->assertSame( $latest_update, bp_get_user_meta( $u1, 'bp_latest_update', true ) ); 1976 1976 } 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 } 1977 2002 }
Note: See TracChangeset
for help on using the changeset viewer.