Making WordPress.org


Ignore:
Timestamp:
06/18/2016 03:07:08 PM (9 years ago)
Author:
obenland
Message:

Plugin Directory: Consolidate review queries.

See #1719, #1579.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin.php

    r3289 r3439  
    33use WordPressdotorg\Plugin_Directory\Plugin_Directory;
    44use WordPressdotorg\Plugin_Directory\Template;
     5use WordPressdotorg\Plugin_Directory\Tools;
    56use WordPressdotorg\Plugin_Directory\API\Base;
    67use WP_REST_Server;
     
    187188    protected function get_plugin_reviews_markup( $plugin_slug ) {
    188189        $output = '';
    189         foreach ( $this->get_plugin_reviews_data( $plugin_slug ) as $review ) {
     190        foreach ( Tools::get_plugin_reviews( $plugin_slug ) as $review ) {
    190191            $output .= $this->get_plugin_reviews_markup_singular( $review );
    191192        }
     
    245246
    246247    }
    247 
    248     /**
    249      * Fetch the latest 10 reviews for a given plugin from the database.
    250      *
    251      * This uses raw SQL to query the bbPress tables to fetch reviews.
    252      *
    253      * @param string $plugin_slug The slug of the plugin.
    254      * @return array An array of review details.
    255      */
    256     protected function get_plugin_reviews_data( $plugin_slug ) {
    257         global $wpdb;
    258         if ( ! defined( 'WPORGPATH' ) || ! defined( 'CUSTOM_USER_TABLE' ) ) {
    259             // Reviews are stored in the main supoport forum, which isn't open source yet.
    260             return array();
    261         }
    262 
    263         if ( $reviews = wp_cache_get( $plugin_slug, 'reviews' ) ) {
    264             return $reviews;
    265         }
    266 
    267         // The forums are the source for users, and also where reviews live.
    268         $table_prefix = str_replace( 'users', '', CUSTOM_USER_TABLE );
    269         $forum_id = 18; // The Review Forums ID
    270 
    271         $reviews = $wpdb->get_results( $wpdb->prepare( "
    272             SELECT
    273                 t.topic_id, t.topic_title, t.topic_poster, t.topic_start_time,
    274                 p.post_text,
    275                 tm_wp.meta_value as wp_version
    276             FROM {$table_prefix}topics AS t
    277             JOIN {$table_prefix}meta AS tm ON ( tm.object_type = 'bb_topic' AND t.topic_id = tm.object_id AND tm.meta_key = 'is_plugin' )
    278             JOIN {$table_prefix}posts as p ON ( t.topic_id = p.topic_id AND post_status = 0 AND post_position = 1 )
    279             LEFT JOIN {$table_prefix}meta AS tm_wp ON ( tm_wp.object_type = 'bb_topic' AND t.topic_id = tm_wp.object_id AND tm_wp.meta_key = 'wp_version' )
    280             WHERE t.forum_id = %d AND t.topic_status = 0 AND t.topic_sticky = 0 AND tm.meta_value = %s
    281             ORDER BY t.topic_start_time DESC
    282             LIMIT 10",
    283             $forum_id,
    284             $plugin_slug
    285         ) );
    286 
    287         wp_cache_set( $plugin_slug, $reviews, 'reviews' );
    288         return $reviews;
    289     }
    290248}
    291249
Note: See TracChangeset for help on using the changeset viewer.