Skip to:
Content

bbPress.org


Ignore:
Timestamp:
05/30/2016 10:28:36 AM (8 years ago)
Author:
netweb
Message:

General Performance: Introduce increase/decrease helper count functions

Previously when a new topic or reply was created, a bunch of queries to recalculate the topic and reply counts for topics and forums were ran. Now these have been replaced with more efficient increase/decrease helper functions to get the current value and just "bump" the count based on the action (new topic-reply/split-topic/move-topic/spam-trash-topic/etc...)

Props thebrandonallen, tharsheblows, netweb
See #1799

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/replies/functions.php

    r6032 r6036  
    6666    bbp_update_reply( $reply_id, $reply_meta['topic_id'], $reply_meta['forum_id'], array(), $reply_data['post_author'], false, $reply_meta['reply_to'] );
    6767
     68    /**
     69     * Fires after reply has been inserted via `bbp_insert_reply`.
     70     *
     71     * @since 2.6.0 bbPress (r6036)
     72     *
     73     * @param int $reply_id               The reply id.
     74     * @param int $reply_meta['topic_id'] The reply topic meta.
     75     * @param int $reply_meta['forum_id'] The reply forum meta.
     76     */
     77    do_action( 'bbp_insert_reply', (int) $reply_id, (int) $reply_meta['topic_id'], (int) $reply_meta['forum_id'] );
     78
    6879    // Return new reply ID
    6980    return $reply_id;
     81}
     82
     83/**
     84 * Update counts after a reply is inserted via `bbp_insert_reply`.
     85 *
     86 * @since 2.6.0 bbPress (r6036)
     87 *
     88 * @param int $reply_id The reply id.
     89 * @param int $topic_id The topic id.
     90 * @param int $forum_id The forum id.
     91 *
     92 * @uses bbp_get_reply_status() To get the reply status
     93 * @uses bbp_get_public_status_id() To get the public status id
     94 * @uses bbp_increase_topic_reply_count() To bump the topics reply count by 1
     95 * @uses bbp_increase_forum_reply_count() To bump the forums reply count by 1
     96 * @uses bbp_increase_topic_reply_count_hidden() To bump the topics hidden reply
     97 *                                               count by 1
     98 *
     99 * @return void
     100 */
     101function bbp_insert_reply_update_counts( $reply_id = 0, $topic_id = 0, $forum_id = 0 ) {
     102
     103    // If the reply is public, update the forum/topic reply counts.
     104    if ( bbp_get_reply_status( $reply_id ) === bbp_get_public_status_id() ) {
     105        bbp_increase_topic_reply_count( $topic_id );
     106        bbp_increase_forum_reply_count( $forum_id );
     107
     108    // If the reply isn't public only update the topic reply hidden count.
     109    } else {
     110        bbp_increase_topic_reply_count_hidden( $topic_id );
     111    }
    70112}
    71113
     
    9781020
    9791021                // Counts
    980                 bbp_update_topic_voice_count       ( $ancestor );
    981                 bbp_update_topic_reply_count       ( $ancestor );
    982                 bbp_update_topic_reply_count_hidden( $ancestor );
     1022                bbp_update_topic_voice_count( $ancestor );
     1023
     1024                // Only update reply count if we're deleting a reply, or in the dashboard.
     1025                if ( in_array( current_filter(), array( 'bbp_deleted_reply', 'save_post' ), true ) ) {
     1026                    bbp_update_topic_reply_count(        $ancestor );
     1027                    bbp_update_topic_reply_count_hidden( $ancestor );
     1028                }
    9831029
    9841030            // Forum meta relating to most recent topic
     
    10041050
    10051051                // Counts
    1006                 bbp_update_forum_reply_count( $ancestor );
     1052                // Only update reply count if we're deleting a reply, or in the dashboard.
     1053                if ( in_array( current_filter(), array( 'bbp_deleted_reply', 'save_post' ), true ) ) {
     1054                    bbp_update_forum_reply_count( $ancestor );
     1055                }
    10071056            }
    10081057        }
Note: See TracChangeset for help on using the changeset viewer.