Skip to:
Content

bbPress.org


Ignore:
Timestamp:
07/05/2018 06:03:38 AM (7 years ago)
Author:
johnjamesjacoby
Message:

Counts: Introduce a cacheable parent/type/status wrapper, filter helpers.

This change introduces a common query function for totalling up all counts by type & status, and caching the results for later usages. By doing this, we can avoid running multiple queries for the same public or non-public counts.

Also uses bbp_number_not_negative() in a few places where negative counts are never allowed.

File:
1 edited

Legend:

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

    r6793 r6827  
    24712471
    24722472    // Get replies of topic if not passed
    2473     if ( empty( $reply_count ) ) {
    2474         $reply_count = bbp_get_public_child_count( $topic_id, bbp_get_reply_post_type() );
    2475     }
    2476 
    2477     $reply_count = (int) $reply_count;
     2473    $reply_count = empty( $reply_count )
     2474        ? bbp_get_public_child_count( $topic_id, bbp_get_reply_post_type() )
     2475        : (int) $reply_count;
    24782476
    24792477    update_post_meta( $topic_id, '_bbp_reply_count', $reply_count );
     
    25012499
    25022500    // Get replies of topic
    2503     if ( empty( $reply_count ) ) {
    2504         $statuses    = bbp_get_non_public_topic_statuses();
    2505         $post_status = "'" . implode( "','", $statuses ) . "'";
    2506         $bbp_db      = bbp_db();
    2507         $query       = $bbp_db->prepare( "SELECT COUNT(ID) FROM {$bbp_db->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = %s", $topic_id, bbp_get_reply_post_type() );
    2508         $reply_count = $bbp_db->get_var( $query );
    2509     }
    2510 
    2511     $reply_count = (int) $reply_count;
     2501    $reply_count = empty( $reply_count )
     2502        ? bbp_get_non_public_child_count( $topic_id, 'reply' )
     2503        : (int) $reply_count;
    25122504
    25132505    update_post_meta( $topic_id, '_bbp_reply_count_hidden', $reply_count );
Note: See TracChangeset for help on using the changeset viewer.