WordPress.org

Making WordPress.org

Changeset 3218


Ignore:
Timestamp:
05/23/2016 03:47:14 PM (6 years ago)
Author:
obenland
Message:

Plugin Directory: Cache front page queries for a day.

The results of featured and beta plugins don't change very often, the results
of popular plugins can change on each reload as there are more than four
plugins with 1 million+ installs, and it decreases db lookups.

See #1719.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/front-page.php

    r3208 r3218  
    2727
    2828        <?php foreach ( $sections as $section_slug => $section_title ) :
    29             $section_args = array(
    30                 'post_type'       => 'plugin',
    31                 'posts_per_page'  => 4,
    32                 'plugin_category' => $section_slug,
    33             );
     29            if ( false === ( $section_query = wp_cache_get( "{$section_slug}:front_page", 'wporg-plugins' ) ) ) :
     30                $section_args = array(
     31                    'post_type'       => 'plugin',
     32                    'posts_per_page'  => 4,
     33                    'plugin_category' => $section_slug,
     34                );
    3435
    35             if ( 'popular' === $section_slug ) :
    36                 $section_args['meta_key'] = 'active_installs';
    37                 $section_args['orderby']  = 'meta_value_num';
    38                 unset( $section_args['plugin_category'] );
     36                if ( 'popular' === $section_slug ) :
     37                    $section_args['meta_key'] = 'active_installs';
     38                    $section_args['orderby']  = 'meta_value_num';
     39                    unset( $section_args['plugin_category'] );
     40                endif;
     41
     42                $section_query = new \WP_Query( $section_args );
     43                wp_cache_set( "{$section_slug}:front_page", $section_query, 'wporg-plugins', DAY_IN_SECONDS );
    3944            endif;
    40 
    41             $section_query = new \WP_Query( $section_args );
    4245        ?>
    4346
Note: See TracChangeset for help on using the changeset viewer.