Making WordPress.org


Ignore:
Timestamp:
04/05/2014 05:18:21 PM (10 years ago)
Author:
johnjamesjacoby
Message:

BuddyPress.org: Add 5 minute output cache to front page topics, to speed up front page render times.

Location:
sites/trunk/buddypress.org/public_html/wp-content/themes/bb-base
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/buddypress.org/public_html/wp-content/themes/bb-base/functions.php

    r498 r504  
    307307    return $rating_html;
    308308}
     309
     310/**
     311 * Output front page topics
     312 *
     313 * @author johnjamesjacoby
     314 * @uses bb_base_get_homepage_topics()
     315 * @param mixed $args
     316 * @return void
     317 */
     318function bb_base_homepage_topics( $args = false ) {
     319    echo bb_base_get_homepage_topics( $args );
     320}
     321
     322/**
     323 * Get front page topics output and stash it for 5 minutes
     324 *
     325 * @author johnjamesjacoby
     326 * @param mixed $args
     327 * @return HTML
     328 */
     329function bb_base_get_homepage_topics( $args = false ) {
     330
     331    // Transient settings
     332    $expiration    = MINUTE_IN_SECONDS * 5;
     333    $transient_key = 'bb_base_homepage_topics';
     334    $output        = get_transient( $transient_key );
     335
     336    // No transient found, so query for topics again
     337    if ( false === $output ) {
     338
     339        // Setup some default topics query args
     340        $r = wp_parse_args( $args, array(
     341            's'              => '',
     342            'posts_per_page' => 5,
     343            'max_num_pages'  => 1,
     344            'paged'          => 1,
     345            'show_stickies'  => false
     346        ) );
     347
     348        // Look for topics
     349        if ( bbp_has_topics( $r ) ) {
     350            $output = bbp_buffer_template_part( 'loop',     'topics',    false );
     351        } else {
     352            $output = bbp_buffer_template_part( 'feedback', 'no-topics', false );
     353        }
     354
     355        // Set the transient
     356        set_transient( $transient_key, $output, $expiration );
     357    }
     358
     359    // Return the output
     360    return $output;
     361}
  • sites/trunk/buddypress.org/public_html/wp-content/themes/bb-base/page-homepage.php

    r503 r504  
    1010<div id="bbpress-forums">
    1111
    12     <?php if ( bbp_has_topics( array( 's' => '', 'posts_per_page' => 5, 'max_num_pages' => 1, 'paged' => 1, 'show_stickies' => false ) ) ) : ?>
    13 
    14         <?php bbp_get_template_part( 'loop',     'topics'    ); ?>
    15 
    16     <?php else : ?>
    17 
    18         <?php bbp_get_template_part( 'feedback', 'no-topics' ); ?>
    19 
    20     <?php endif; ?>
     12    <?php bb_base_homepage_topics(); ?>
    2113
    2214</div>
Note: See TracChangeset for help on using the changeset viewer.