Making WordPress.org

Ticket #2967: 2967.patch

File 2967.patch, 1.9 KB (added by ketuchetan, 8 years ago)
  • trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support/functions.php

     
    248248                return 0;
    249249        }
    250250
    251         $count = (int) $wpdb->get_var( $wpdb->prepare(
    252                 "SELECT COUNT(*)
     251        // Check cache.
     252        $count = wp_cache_get( 'user_topics_count_'.$user_id, 'user-topics-count' );
     253        if ( false === $count ) {
     254                $count = (int) $wpdb->get_var( $wpdb->prepare(
     255                        "SELECT COUNT(*)
    253256                        FROM {$wpdb->posts}
    254257                        WHERE post_type = 'topic'
    255258                                AND post_status IN ( 'publish', 'closed' )
    256259                                AND post_parent <> %d
    257260                                AND post_author = %d",
    258                 WordPressdotorg\Forums\Plugin::REVIEWS_FORUM_ID,
    259                 $user_id
    260         ) );
     261                        WordPressdotorg\Forums\Plugin::REVIEWS_FORUM_ID,
     262                        $user_id
     263                ) );
     264                wp_cache_add(  'user_topics_count_'.$user_id, $count, 'user-topics-count' );
     265        }
    261266
    262267        return $count;
    263268}
     
    282287                return 0;
    283288        }
    284289
    285         $count = (int) $wpdb->get_var( $wpdb->prepare(
    286                 "SELECT COUNT(*)
     290        // Check cache.
     291        $count = wp_cache_get( 'user_reviews_count_'.$user_id, 'user-reviews-count' );
     292        if ( false === $count ) {
     293                $count = (int) $wpdb->get_var( $wpdb->prepare(
     294                        "SELECT COUNT(*)
    287295                        FROM {$wpdb->posts}
    288296                        WHERE post_type = 'topic'
    289297                                AND post_status IN ( 'publish', 'closed' )
    290298                                AND post_parent = %d
    291299                                AND post_author = %d",
    292                 WordPressdotorg\Forums\Plugin::REVIEWS_FORUM_ID,
    293                 $user_id
    294         ) );
     300                        WordPressdotorg\Forums\Plugin::REVIEWS_FORUM_ID,
     301                        $user_id
     302                ) );
     303                wp_cache_add(  'user_reviews_count_'.$user_id, $count, 'user-reviews-count' );
     304        }
    295305
    296306        return $count;
    297307}
     
    530540
    531541        return $user_can_stick;
    532542}
    533  
     543
    534544/**
    535545 * Correct reply URLs for pending posts.
    536546 *