Skip to:
Content

bbPress.org


Ignore:
Timestamp:
06/12/2017 05:41:49 PM (8 years ago)
Author:
johnjamesjacoby
Message:

Engagements: Keep topic engagement counts up-to-date.

This changes the way the old 'voice count' works with the new engagements API in the following ways:

  • Introduce new function to update voice count meta when necessary
  • Modify recalculation function with a $force parameter, and only recalculate the counts when the engagements have changed by default
  • Hook the above functions in where appropriate, largely when deleting replies (this is a unique case where a fully deleted reply needs to check if the author of the current reply has a previously public reply in that same topic already, which should not trigger a recalculation.)
  • We are silently moving the bbp_delete_ actions onto the before_delete_post hook, so that all term & meta-data is available to them (which helps with race conditions mentioned in r6528)

Engagements are now hooked in and listening in the most efficient way possible, at least until a common & shared walker is introduced for the entire tree.

See: #3068.

File:
1 edited

Legend:

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

    r6516 r6529  
    944944        if ( empty( $forum_id )  ) {
    945945            $forum_id = bbp_get_topic_forum_id( $topic_id );
    946 
    947             // Make every effort to get forum id
    948             // https://bbpress.trac.wordpress.org/ticket/2529
    949             if ( empty( $forum_id ) && ( current_filter() === 'bbp_deleted_topic' ) ) {
    950                 $forum_id = get_post_field( 'post_parent', $topic_id );
    951             }
    952946        }
    953947
     
    29832977function bbp_update_topic_voice_count( $topic_id = 0 ) {
    29842978
    2985     // Get the old voices
     2979    // If it's a reply, then get the parent (topic id)
     2980    $topic_id = bbp_is_reply( $topic_id )
     2981        ? bbp_get_reply_topic_id( $topic_id )
     2982        : bbp_get_topic_id( $topic_id );
     2983
     2984    // Bail if no topic ID
     2985    if ( empty( $topic_id ) ) {
     2986        return;
     2987    }
     2988
     2989    // Count the engagements
    29862990    $count = count( bbp_get_topic_engagements( $topic_id ) );
    29872991
     
    38743878 * Called after deleting a topic
    38753879 *
     3880 * @since 2.0.0 bbPress (r2993)
     3881 *
    38763882 * @uses bbp_get_topic_id() To get the topic id
    38773883 * @uses bbp_is_topic() To check if the passed id is a topic
     
    38913897 * Called after trashing a topic
    38923898 *
     3899 * @since 2.0.0 bbPress (r2993)
     3900 *
    38933901 * @uses bbp_get_topic_id() To get the topic id
    38943902 * @uses bbp_is_topic() To check if the passed id is a topic
     
    39073915/**
    39083916 * Called after untrashing a topic
     3917 *
     3918 * @since 2.0.0 bbPress (r2993)
    39093919 *
    39103920 * @uses bbp_get_topic_id() To get the topic id
Note: See TracChangeset for help on using the changeset viewer.