Skip to:
Content

bbPress.org

Ticket #1925: 0001-bbPress-performance-enhancements-http-bbpress.trac.w.patch

File 0001-bbPress-performance-enhancements-http-bbpress.trac.w.patch, 11.2 KB (added by vibol, 11 years ago)
  • wp-content/plugins/bbpress/includes/admin/tools.php

    From ee2113584c89afd31cab1f1691bfd8f11d87b858 Mon Sep 17 00:00:00 2001
    From: Vibol Hou <vibol@hou.cc>
    Date: Thu, 7 Feb 2013 16:51:03 -0800
    Subject: [PATCH] bbPress performance enhancements /
     http://bbpress.trac.wordpress.org/ticket/1925
    
    ---
     .../plugins/bbpress/includes/admin/tools.php       |   32 +++++++++++---------
     .../plugins/bbpress/includes/common/widgets.php    |    3 +-
     .../plugins/bbpress/includes/forums/functions.php  |   15 ++++-----
     .../bbpress/includes/forums/template-tags.php      |    2 +-
     .../plugins/bbpress/includes/topics/functions.php  |    9 +++---
     .../bbpress/includes/topics/template-tags.php      |    8 ++---
     6 files changed, 36 insertions(+), 33 deletions(-)
     mode change 100644 => 100755 wp-content/plugins/bbpress/includes/admin/tools.php
     mode change 100644 => 100755 wp-content/plugins/bbpress/includes/forums/functions.php
     mode change 100644 => 100755 wp-content/plugins/bbpress/includes/forums/template-tags.php
     mode change 100644 => 100755 wp-content/plugins/bbpress/includes/replies/functions.php
     mode change 100644 => 100755 wp-content/plugins/bbpress/includes/topics/functions.php
    
    diff --git a/wp-content/plugins/bbpress/includes/admin/tools.php b/wp-content/plugins/bbpress/includes/admin/tools.php
    old mode 100644
    new mode 100755
    index ad608ad..6481e92
    a b function bbp_admin_repair_freshness() { 
    744744        $statement = __( 'Recomputing latest post in every topic and forum&hellip; %s', 'bbpress' );
    745745        $result    = __( 'Failed!', 'bbpress' );
    746746
    747         // First, delete everything.
     747        /* First, delete everything.
     748           We're not using _bbp_last_active_time anymore, but
     749           it makes sense to keep it here to help migrate to the
     750           new data model.
     751        */
    748752        if ( is_wp_error( $wpdb->query( "DELETE FROM `$wpdb->postmeta` WHERE `meta_key` IN ( '_bbp_last_reply_id', '_bbp_last_topic_id', '_bbp_last_active_id', '_bbp_last_active_time' );" ) ) )
    749753                return array( 1, sprintf( $statement, $result ) );
    750754
    function bbp_admin_repair_freshness() { 
    797801                return array( 7, sprintf( $statement, $result ) );
    798802
    799803        // Give topics with replies their last update time.
    800         if ( is_wp_error( $wpdb->query( "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`)
    801                         ( SELECT `topic`.`ID`, '_bbp_last_active_time', MAX( `reply`.`post_date` )
    802                         FROM `$wpdb->posts` AS `topic` INNER JOIN `$wpdb->posts` AS `reply` ON `topic`.`ID` = `reply`.`post_parent`
    803                         WHERE `reply`.`post_status` IN ( '" . bbp_get_public_status_id() . "' ) AND `topic`.`post_type` = 'topic' AND `reply`.`post_type` = 'reply'
    804                         GROUP BY `topic`.`ID` );" ) ) )
    805                 return array( 8, sprintf( $statement, $result ) );
     804        $sql = $wpdb->prepare(
     805                "UPDATE $wpdb->posts p1
     806                        LEFT JOIN (SELECT  post_parent,
     807                                                        MAX(post_date) AS max_date
     808                                                        FROM $wpdb->posts
     809                                                        WHERE post_status = %s AND post_type = 'reply'
     810                                                        GROUP BY post_parent
     811                                                ) p2
     812                        ON p1.ID = p2.post_parent
     813                        SET p1.post_modified = p2.max_date", bbp_get_public_status_id()
     814        );
    806815
    807         // Give topics without replies their last update time.
    808         if ( is_wp_error( $wpdb->query( "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`)
    809                         ( SELECT `ID`, '_bbp_last_active_time', `post_date`
    810                         FROM `$wpdb->posts` AS `topic` LEFT JOIN `$wpdb->postmeta` AS `reply`
    811                         ON `topic`.`ID` = `reply`.`post_id` AND `reply`.`meta_key` = '_bbp_last_active_time'
    812                         WHERE `reply`.`meta_id` IS NULL AND `topic`.`post_type` = 'topic' );" ) ) )
    813                 return array( 9, sprintf( $statement, $result ) );
     816        if ( is_wp_error( $wpdb->query( $sql ) ) )
     817                return array( 8, sprintf( $statement, $result ) );
    814818
    815819        // Forums need to know what their last active item is as well. Now it gets a bit more complex to do in the database.
    816820        $forums = $wpdb->get_col( "SELECT `ID` FROM `$wpdb->posts` WHERE `post_type` = 'forum' and `post_status` != 'auto-draft';" );
  • wp-content/plugins/bbpress/includes/common/widgets.php

    diff --git a/wp-content/plugins/bbpress/includes/common/widgets.php b/wp-content/plugins/bbpress/includes/common/widgets.php
    index 42c0b3a..f0e6c83 100644
    a b class BBP_Topics_Widget extends WP_Widget { 
    544544                                        'posts_per_page' => $max_shown,
    545545                                        'post_status'    => join( ',', array( bbp_get_public_status_id(), bbp_get_closed_status_id() ) ),
    546546                                        'show_stickes'   => false,
    547                                         'meta_key'       => '_bbp_last_active_time',
    548                                         'orderby'        => 'meta_value',
     547                                        'orderby'        => 'modified',
    549548                                        'order'          => 'DESC',
    550549                                        'meta_query'     => array( bbp_exclude_forum_ids( 'meta_query' ) )
    551550                                );
  • wp-content/plugins/bbpress/includes/forums/functions.php

    diff --git a/wp-content/plugins/bbpress/includes/forums/functions.php b/wp-content/plugins/bbpress/includes/forums/functions.php
    old mode 100644
    new mode 100755
    index 8011cda..db1be1b
    a b function bbp_update_forum_last_topic_id( $forum_id = 0, $topic_id = 0 ) { 
    11021102                $post_vars = array(
    11031103                        'post_parent' => $forum_id,
    11041104                        'post_type'   => bbp_get_topic_post_type(),
    1105                         'meta_key'    => '_bbp_last_active_time',
    1106                         'orderby'     => 'meta_value',
     1105                        'orderby'     => 'modified',
     1106                        'order'       => 'DESC',
    11071107                        'numberposts' => 1
    11081108                );
    11091109
    function bbp_update_forum_last_active_id( $forum_id = 0, $active_id = 0 ) { 
    12721272 * @return bool True on success, false on failure
    12731273 */
    12741274function bbp_update_forum_last_active_time( $forum_id = 0, $new_time = '' ) {
     1275        global $wpdb;
    12751276        $forum_id = bbp_get_forum_id( $forum_id );
    1276 
    12771277        // Check time and use current if empty
    12781278        if ( empty( $new_time ) )
    12791279                $new_time = get_post_field( 'post_date', bbp_get_forum_last_active_id( $forum_id ) );
    12801280
    12811281        // Update only if there is a time
    1282         if ( !empty( $new_time ) )
    1283                 update_post_meta( $forum_id, '_bbp_last_active_time', $new_time );
     1282        if ( !empty( $new_time ) ) {
     1283                $wpdb->query($wpdb->prepare("UPDATE $wpdb->posts SET post_modified=%s WHERE ID=%d", $new_time, $forum_id));
     1284        }
    12841285
    12851286        return (int) apply_filters( 'bbp_update_forum_last_active', $new_time, $forum_id );
    12861287}
    function bbp_forum_query_subforum_ids( $forum_id ) { 
    17631764 * @return Position change based on sort
    17641765 */
    17651766function _bbp_forum_query_usort_subforum_ids( $a = 0, $b = 0 ) {
    1766         $ta = get_post_meta( $a, '_bbp_last_active_time', true );
    1767         $tb = get_post_meta( $b, '_bbp_last_active_time', true );
     1767        $ta = get_post_field( 'post_modified', $a );
     1768        $tb = get_post_field( 'post_modified', $b );
    17681769        return ( $ta < $tb ) ? -1 : 1;
    17691770}
    17701771
  • wp-content/plugins/bbpress/includes/forums/template-tags.php

    diff --git a/wp-content/plugins/bbpress/includes/forums/template-tags.php b/wp-content/plugins/bbpress/includes/forums/template-tags.php
    old mode 100644
    new mode 100755
    index d33b75d..5f34bc0
    a b function bbp_forum_last_active_time( $forum_id = 0 ) { 
    452452        function bbp_get_forum_last_active_time( $forum_id = 0 ) {
    453453                $forum_id = bbp_get_forum_id( $forum_id );
    454454
    455                 $last_active = get_post_meta( $forum_id, '_bbp_last_active_time', true );
     455                $last_active = get_post_field( 'post_modified', $forum_id );
    456456                if ( empty( $last_active ) ) {
    457457                        $reply_id = bbp_get_forum_last_reply_id( $forum_id );
    458458                        if ( !empty( $reply_id ) ) {
  • wp-content/plugins/bbpress/includes/topics/functions.php

    diff --git a/wp-content/plugins/bbpress/includes/replies/functions.php b/wp-content/plugins/bbpress/includes/replies/functions.php
    old mode 100644
    new mode 100755
    diff --git a/wp-content/plugins/bbpress/includes/topics/functions.php b/wp-content/plugins/bbpress/includes/topics/functions.php
    old mode 100644
    new mode 100755
    index b122367..4a9276b
    a b function bbp_update_topic_last_active_id( $topic_id = 0, $active_id = 0 ) { 
    23972397 * @return bool True on success, false on failure
    23982398 */
    23992399function bbp_update_topic_last_active_time( $topic_id = 0, $new_time = '' ) {
    2400 
     2400        global $wpdb;
    24012401        // If it's a reply, then get the parent (topic id)
    24022402        if ( bbp_is_reply( $topic_id ) )
    24032403                $topic_id = bbp_get_reply_topic_id( $topic_id );
    function bbp_update_topic_last_active_time( $topic_id = 0, $new_time = '' ) { 
    24092409                $new_time = get_post_field( 'post_date', bbp_get_public_child_last_id( $topic_id, bbp_get_reply_post_type() ) );
    24102410
    24112411        // Update only if published
    2412         if ( !empty( $new_time ) )
    2413                 update_post_meta( $topic_id, '_bbp_last_active_time', $new_time );
     2412        if ( !empty( $new_time ) ) {
     2413                $wpdb->query($wpdb->prepare("UPDATE $wpdb->posts SET post_modified=%s WHERE ID=%d", $new_time, $topic_id));
     2414        }
    24142415
    24152416        return apply_filters( 'bbp_update_topic_last_active_time', $new_time, $topic_id );
    24162417}
    function bbp_display_topics_feed_rss2( $topics_query = array() ) { 
    32553256                                        <guid><?php bbp_topic_permalink(); ?></guid>
    32563257                                        <title><![CDATA[<?php bbp_topic_title(); ?>]]></title>
    32573258                                        <link><?php bbp_topic_permalink(); ?></link>
    3258                                         <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_meta( bbp_get_topic_id(), '_bbp_last_active_time', true ) ); ?></pubDate>
     3259                                        <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_field( 'post_modified', bbp_get_topic_id() ) ); ?></pubDate>
    32593260                                        <dc:creator><?php the_author() ?></dc:creator>
    32603261
    32613262                                        <?php if ( !post_password_required() ) : ?>
  • wp-content/plugins/bbpress/includes/topics/template-tags.php

    diff --git a/wp-content/plugins/bbpress/includes/topics/template-tags.php b/wp-content/plugins/bbpress/includes/topics/template-tags.php
    index eb360fc..6e6d354 100644
    a b function bbp_has_topics( $args = '' ) { 
    101101                'post_type'      => bbp_get_topic_post_type(), // Narrow query down to bbPress topics
    102102                'post_parent'    => $default_post_parent,      // Forum ID
    103103                'post_status'    => $default_post_status,      // Post Status
    104                 'meta_key'       => '_bbp_last_active_time',   // Make sure topic has some last activity time
    105                 'orderby'        => 'meta_value',              // 'meta_value', 'author', 'date', 'title', 'modified', 'parent', rand',
     104                'orderby'        => 'modified',                // 'meta_value', 'author', 'date', 'title', 'modified', 'parent', rand',
    106105                'order'          => 'DESC',                    // 'ASC', 'DESC'
    107106                'posts_per_page' => bbp_get_topics_per_page(), // Topics per page
    108107                'paged'          => bbp_get_paged(),           // Page Number
    function bbp_has_topics( $args = '' ) { 
    186185                                        'post_type'   => bbp_get_topic_post_type(),
    187186                                        'post_parent' => 'any',
    188187                                        'post_status' => $default_post_status,
    189                                         'meta_key'    => '_bbp_last_active_time',
    190                                         'orderby'     => 'meta_value',
     188                                        'orderby'     => 'modified',
    191189                                        'order'       => 'DESC',
    192190                                        'include'     => $stickies
    193191                                );
    function bbp_topic_last_active_time( $topic_id = 0 ) { 
    16471645                $topic_id = bbp_get_topic_id( $topic_id );
    16481646
    16491647                // Try to get the most accurate freshness time possible
    1650                 $last_active = get_post_meta( $topic_id, '_bbp_last_active_time', true );
     1648                $last_active = get_post_field( 'post_modified', $topic_id );
    16511649                if ( empty( $last_active ) ) {
    16521650                        $reply_id = bbp_get_topic_last_reply_id( $topic_id );
    16531651                        if ( !empty( $reply_id ) ) {