Ticket #2915: 2915.2.diff
| File 2915.2.diff, 3.7 KB (added by , 10 years ago) |
|---|
-
src/includes/forums/functions.php
1649 1649 1650 1650 // Don't count replies if the forum is a category 1651 1651 $reply_count = 0; 1652 $topic_ids = bbp_forum_query_topic_ids( $forum_id ); 1653 if ( ! empty( $topic_ids ) ) { 1654 $query = new WP_Query( array( 1655 'fields' => 'ids', 1656 'post_parent__in' => $topic_ids, 1657 'post_status' => bbp_get_public_status_id(), 1658 'post_type' => bbp_get_reply_post_type(), 1652 $all_topic_ids = bbp_forum_query_topic_ids( $forum_id ); 1659 1653 1660 // Maybe change these later 1661 'posts_per_page' => -1, 1662 'update_post_term_cache' => false, 1663 'update_post_meta_cache' => false, 1664 'ignore_sticky_posts' => true, 1665 ) ); 1666 $reply_count = ! empty( $query->posts ) ? count( $query->posts ) : 0; 1667 unset( $query ); 1654 $topic_ids_chunks = array_chunk( $all_topic_ids, 1000 ); 1655 1656 1657 foreach( $topic_ids_chunks as $topic_ids ){ 1658 1659 $chunk_reply_count = 0; 1660 if ( ! empty( $topic_ids ) ) { 1661 $query = new WP_Query( array( 1662 'fields' => 'ids', 1663 'post_parent__in' => $topic_ids, 1664 'post_status' => bbp_get_public_status_id(), 1665 'post_type' => bbp_get_reply_post_type(), 1666 1667 // Maybe change these later 1668 'posts_per_page' => -1, 1669 'update_post_term_cache' => false, 1670 'update_post_meta_cache' => false, 1671 'ignore_sticky_posts' => true, 1672 ) ); 1673 $chunk_reply_count = ! empty( $query->posts ) ? count( $query->posts ) : 0; 1674 $reply_count += $chunk_reply_count; 1675 unset( $query ); 1676 } 1668 1677 } 1669 1678 1670 1679 // Calculate total replies in this forum … … 2069 2078 */ 2070 2079 function bbp_forum_query_topic_ids( $forum_id ) { 2071 2080 $topic_ids = bbp_get_public_child_ids( $forum_id, bbp_get_topic_post_type() ); 2072 2073 2081 return (array) apply_filters( 'bbp_forum_query_topic_ids', $topic_ids, $forum_id ); 2074 2082 } 2075 2083 … … 2111 2119 2112 2120 // Validate forum 2113 2121 $forum_id = bbp_get_forum_id( $forum_id ); 2122 $last_reply_id = 0; 2114 2123 2115 2124 // Get topic ID's if none were passed 2116 2125 if ( empty( $topic_ids ) ) { … … 2117 2126 $topic_ids = bbp_forum_query_topic_ids( $forum_id ); 2118 2127 } 2119 2128 2120 $query = new WP_Query( array( 2121 'fields' => 'ids', 2122 'post_parent__in' => $topic_ids, 2123 'post_status' => bbp_get_public_status_id(), 2124 'post_type' => bbp_get_reply_post_type(), 2129 $topic_ids_chunks = ( empty( array_chunk( $topic_ids, 1000 ) ) ) ? array( 0 => array() ) : array_chunk( $topic_ids, 1000 ); // this needs an empty array if it's empty 2125 2130 2126 // Maybe change these later2127 'posts_per_page' => 1,2128 'update_post_term_cache' => false,2129 'update_post_meta_cache' => false,2130 'ignore_sticky_posts' => true,2131 ) );2132 $reply_id = array_shift( $query->posts );2133 unset( $query );2134 2131 2135 return (int) apply_filters( 'bbp_forum_query_last_reply_id', $reply_id, $forum_id ); 2132 foreach( $topic_ids_chunks as $topic_ids ){ 2133 2134 $query = new WP_Query( array( 2135 'fields' => 'ids', 2136 'post_parent__in' => $topic_ids, 2137 'post_status' => bbp_get_public_status_id(), 2138 'post_type' => bbp_get_reply_post_type(), 2139 2140 // Maybe change these later 2141 'posts_per_page' => 1, 2142 'update_post_term_cache' => false, 2143 'update_post_meta_cache' => false, 2144 'ignore_sticky_posts' => true, 2145 ) ); 2146 $chunk_reply_id = array_shift( $query->posts ); 2147 $last_reply_id = ( $chunk_reply_id > $last_reply_id ) ? $chunk_reply_id : $last_reply_id; // @todo fix ID / date conflation 2148 2149 unset( $query ); 2150 } 2151 2152 2153 return (int) apply_filters( 'bbp_forum_query_last_reply_id', $last_reply_id, $forum_id ); 2136 2154 } 2137 2155 2138 2156 /** Listeners *****************************************************************/
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)