Making WordPress.org

Changeset 3440


Ignore:
Timestamp:
06/18/2016 03:25:56 PM (10 years ago)
Author:
obenland
Message:

Plugin Directory: Revert [3439] until we have caching figured out.

See #1719, #1579.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
Files:
3 edited

Legend:

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

    r3439 r3440  
    33use WordPressdotorg\Plugin_Directory\Plugin_Directory;
    44use WordPressdotorg\Plugin_Directory\Template;
    5 use WordPressdotorg\Plugin_Directory\Tools;
    65use WordPressdotorg\Plugin_Directory\API\Base;
    76use WP_REST_Server;
    … …  
    188187        protected function get_plugin_reviews_markup( $plugin_slug ) {
    189188                $output = '';
    190                 foreach ( Tools::get_plugin_reviews( $plugin_slug ) as $review ) {
     189                foreach ( $this->get_plugin_reviews_data( $plugin_slug ) as $review ) {
    191190                        $output .= $this->get_plugin_reviews_markup_singular( $review );
    192191                }
    … …  
    246245
    247246        }
     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        }
    248290}
    249291
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-tools.php

    r3439 r3440  
    3030
    3131        /**
    32          * Fetch the latest 10 reviews for a given plugin from the database.
    33          *
    34          * This uses raw SQL to query the bbPress tables to fetch reviews.
     32         * Returns the two latest reviews of a specific plugin.
    3533         *
    3634         * @global \wpdb $wpdb WordPress database abstraction object.
    3735         *
    38          * @param string $plugin_slug The slug of the plugin.
    39          * @param array  $args        {
    40          *     Optional. Query arguments.
     36         * @todo Populate with review title/content.
    4137         *
    42          *     @type int $number The amount of reviews to return. Default: 10.
    43          * }
    44          * @return array An array of reviews.
     38         * @param string $plugin_slug The plugin slug.
     39         * @return array|false
    4540         */
    46         public static function get_plugin_reviews( $plugin_slug, $args = array() ) {
    47 
    48                 // Reviews are stored in the main support forum, which isn't open sourced yet.
    49                 if ( ! defined( 'WPORGPATH' ) || ! defined( 'CUSTOM_USER_TABLE' ) ) {
    50                         return array();
    51                 }
    52 
    53                 if ( false === ( $reviews = wp_cache_get( $plugin_slug, 'reviews' ) ) ) {
     41        public static function get_plugin_reviews( $plugin_slug ) {
     42                if ( false === ( $reviews = wp_cache_get( "{$plugin_slug}_reviews", 'wporg-plugins' ) ) ) {
    5443                        global $wpdb;
    5544
    56                         $args = wp_parse_args( $args, array(
    57                                 'number' => 10,
    58                         ) );
    59 
    60                         // The forums are the source for users, and also where reviews live.
    61                         $table_prefix = str_replace( 'users', '', CUSTOM_USER_TABLE );
    62                         $forum_id     = 18; // The Review Forums ID.
    63 
    6445                        $reviews = $wpdb->get_results( $wpdb->prepare( "
    65                                 SELECT
    66                                         t.topic_id, t.topic_title, t.topic_poster, t.topic_start_time,
    67                                         p.post_text,
    68                                         ratings.rating,
    69                                         tm_wp.meta_value as wp_version
    70                                 FROM {$table_prefix}topics AS t
    71                                 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' )
    72                                 JOIN {$table_prefix}posts as p ON ( t.topic_id = p.topic_id AND post_status = 0 AND post_position = 1 )
    73                                 JOIN ratings ON (t.topic_id = ratings.review_id )
    74                                 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' )
    75                                 WHERE t.forum_id = %d AND t.topic_status = 0 AND t.topic_sticky = 0 AND tm.meta_value = %s
    76                                 ORDER BY t.topic_start_time DESC
    77                                 LIMIT %d",
    78                                 $forum_id,
    79                                 $plugin_slug,
    80                                 absint( $args['number'] )
    81                         ) );
    82 
    83                         wp_cache_set( $plugin_slug, $reviews, 'reviews' );
     46                        SELECT posts.post_text AS post_content, topics.topic_title AS post_title, ratings.rating AS post_rating, ratings.user_id AS post_author
     47                        FROM ratings
     48                                INNER JOIN minibb_topics AS topics ON ( ratings.review_id = topics.topic_id )
     49                                INNER JOIN minibb_posts AS posts ON ( ratings.review_id = posts.topic_id )
     50                        WHERE
     51                                ratings.object_type = 'plugin' AND
     52                                ratings.object_slug = %s AND
     53                                posts.post_position = 1
     54                        ORDER BY ratings.review_id DESC LIMIT 2", $plugin_slug ) );
     55                        wp_cache_set( "{$plugin_slug}_reviews", $reviews, 'wporg-plugins', HOUR_IN_SECONDS );
    8456                }
    8557
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-reviews.php

    r3439 r3440  
    1515         */
    1616        static function display() {
    17                 $reviews = Tools::get_plugin_reviews( get_post()->post_name, array(
    18                         'number' => 2,
    19                 ) );
     17                $reviews = Tools::get_plugin_reviews( get_post()->post_name );
    2018
    2119                if ( empty( $reviews ) ) {
    … …  
    2927                        <?php
    3028                        foreach ( $reviews as $review ) :
    31                                 $reviewer = get_user_by( 'id', $review->topic_poster );
     29                                $reviewer = get_user_by( 'id', $review->post_author );
    3230                                if ( ! $reviewer ) :
    3331                                        continue;
    … …  
    3937                                        </div><div class="review">
    4038                                                <header>
    41                                                         <h3 class="review-title"><?php echo $review->topic_title; ?></h3>
    42                                                         <?php echo Template::dashicons_stars( $review->rating ); ?>
    43                                                         <span class="review-author author vcard"><a class="url fn n" href="<?php esc_url( 'https://profile.wordpress.org/' . $reviewer->user_nicename . '/' ); ?>"><?php echo Template::encode( $reviewer->display_name ); ?></a></span>
     39                                                        <h3 class="review-title"><?php echo $review->post_title; ?></h3>
     40                                                        <?php echo Template::dashicons_stars( $review->post_rating ); ?>
     41                                                        <span class="review-author author vcard"><a class="url fn n" href="<?php esc_url( get_author_posts_url( $reviewer->ID ) ); ?>"><?php echo Template::encode( $reviewer->display_name ); ?></a></span>
    4442                                                </header>
    45                                                 <p class="review-content"><?php echo $review->post_text; ?></p>
     43                                                <p class="review-content"><?php echo $review->post_content; ?></p>
    4644                                        </div>
    4745                                </article>
Note: See TracChangeset for help on using the changeset viewer.