Changeset 3903
- Timestamp:
- 09/01/2016 03:15:59 AM (8 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-performance-optimizations.php
r3895 r3903 7 7 var $term = null; 8 8 var $query = null; 9 var $bound_id = array(); 9 10 10 11 function __construct() { … … 44 45 } 45 46 46 // has_topics() uses this by default. 47 if ( isset( $r['meta_key'] ) && '_bbp_last_active_time' == $r['meta_key'] ) { 48 unset( $r['meta_key'] ); 49 unset( $r['meta_type'] ); 50 $r['orderby'] = 'ID'; 47 if ( isset( $r['meta_key'] ) ) { 48 // has_topics() uses this by default. 49 if ( '_bbp_last_active_time' == $r['meta_key'] ) { 50 unset( $r['meta_key'] ); 51 unset( $r['meta_type'] ); 52 $r['orderby'] = 'ID'; 53 // Some views use meta key lookups and should only look at known 54 // open topics. 55 } elseif ( ! empty( $r['meta_key'] ) ) { 56 $r['orderby'] = 'ID'; 57 add_filter( 'posts_where', array( $this, 'posts_in_six_months' ) ); 58 } 51 59 } 52 60 53 61 // If this is a forum, limit the number of pages we're dealing with. 54 if ( isset( $r['post_parent'] ) && get_post_type( $r['post_parent'] ) === bbp_get_forum_post_type() ) {62 if ( bbp_is_single_forum() && isset( $r['post_parent'] ) && get_post_type( $r['post_parent'] ) === bbp_get_forum_post_type() ) { 55 63 $r['no_found_rows'] = true; 56 64 add_filter( 'bbp_topic_pagination', array( $this, 'forum_pagination' ) ); … … 59 67 } 60 68 return $r; 69 } 70 71 public function posts_in_last_six_months( $w ) { 72 global $wpdb; 73 74 $bound_id = $this->get_bound_id( '6 MONTH' ); 75 $w .= $wpdb->prepare( " AND ( $wpdb->posts.ID >= %d )", $bound_id ); 76 return $w; 61 77 } 62 78 … … 73 89 // Try SQL. 74 90 if ( ! is_null( $this->query ) ) { 75 $count = $wpdb-> query( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'topic' AND post_status = 'publish'LIMIT 1", $this->query['post_parent'] ) );91 $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'topic' AND post_status IN ( 'publish', 'closed' ) LIMIT 1", $this->query['post_parent'] ) ); 76 92 if ( $count ) { 77 93 $r['total'] = $count / bbp_get_topics_per_page(); 94 update_post_meta( $this->query['post_parent'], '_bbp_topic_count', $count ); 95 update_post_meta( $this->query['post_parent'], '_bbp_total_topic_count', $count ); 78 96 return $r; 79 97 } 80 98 } 81 99 82 // If all else fails...100 // Give a reasonable default to fall back on. 83 101 $r['total'] = 10; 84 102 return $r; … … 108 126 return $term; 109 127 } 128 129 /** 130 * Get the ID from a topic one year ago so that we can only look at topics 131 * after that ID. 132 */ 133 public function get_bound_id( $interval ) { 134 global $wpdb; 135 136 if ( ! in_array( $interval, array( '1 WEEK', '1 MONTH', '6 MONTH', '1 YEAR' ) ) ) { 137 $interval = '1 WEEK'; 138 } 139 140 if ( array_key_exists( $interval, $this->bound_id ) ) { 141 return $this->bound_id[ $interval ]; 142 } 143 144 // Check cache. 145 $cache_key = str_replace( ' ', '-', $interval ); 146 $cache_group = 'topic-bound-ids'; 147 $bound_id = wp_cache_get( $cache_key, $cache_group ); 148 if ( false === $bound_id ) { 149 150 // Use the type_status_date index. 151 $bound_id = $wpdb->get_var( " 152 SELECT `ID` 153 FROM $wpdb->posts 154 WHERE post_type = 'topic' 155 AND post_status IN ( 'publish', 'closed' ) 156 AND post_date < DATE_SUB( NOW(), INTERVAL $interval ) 157 ORDER BY `ID` DESC 158 LIMIT 1 " ); 159 // Set the bound id to 1 if there is not a suitable range. 160 if ( ! $bound_id ) { 161 $bound_id = 1; 162 } 163 $this->bound_id[ $interval ] = $bound_id; 164 165 wp_cache_set( $cache_key, $bound_id, $cache_group, 86400 ); 166 } 167 return $bound_id; 168 } 110 169 } -
sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-plugin.php
r3884 r3903 35 35 $this->performance = new Performance_Optimizations; 36 36 $this->users = new Users; 37 $this->hooks = new Hooks; 37 38 38 39 // These modifications are specific to https://wordpress.org/support/ 39 40 $blog_id = get_current_blog_id(); 40 41 if ( $blog_id && defined( 'WPORG_SUPPORT_FORUMS_BLOGID' ) && WPORG_SUPPORT_FORUMS_BLOGID == $blog_id ) { 42 $this->dropin = new Dropin; 41 43 $this->themes = new Theme_Directory_Compat; 42 44 $this->plugins = new Plugin_Directory_Compat; -
sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/support-forums.php
r3884 r3903 17 17 include( dirname( __FILE__ ) . '/inc/class-plugin.php' ); 18 18 include( dirname( __FILE__ ) . '/inc/class-users.php' ); 19 include( dirname( __FILE__ ) . '/inc/class-dropin.php' ); 20 include( dirname( __FILE__ ) . '/inc/class-hooks.php' ); 19 21 include( dirname( __FILE__ ) . '/inc/class-directory-compat.php' ); 20 22 include( dirname( __FILE__ ) . '/inc/class-theme-directory-compat.php' );
Note: See TracChangeset
for help on using the changeset viewer.