- Timestamp:
- 11/13/2021 03:16:36 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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'];
Note: See TracChangeset
for help on using the changeset viewer.