Skip to:
Content

bbPress.org


Ignore:
Timestamp:
10/01/2026 04:50:02 AM (6 weeks ago)
Author:
johnjamesjacoby
Message:

Blocks: Avoid unused editor queries.

Skip localization when the receiving script is unavailable, preventing front-end editor integrations from triggering expensive choice queries on unrelated logged-in requests. Simplify topic-tag visibility checks by requiring the canonical post parent and stored forum ID to agree, removing redundant forum lists and a correlated anti-join.

In trunk, for 2.7.

Props ocean90.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/common/blocks.php

    r7755 r7763  
    130130                 */
    131131                public function enqueue_block_editor_assets() {
     132
     133                        // Bail if the script receiving this data is unavailable.
     134                        if ( ! wp_script_is( 'bbp-admin-blocks', 'registered' ) ) {
     135                                return;
     136                        }
    132137
    133138                        // Localize script data for the block editor (script is loaded via block.json).
    … …  
    382387                        $placeholders       = implode( ', ', array_fill( 0, count( $statuses ), '%s' ) );
    383388                        $forum_placeholders = implode( ', ', array_fill( 0, count( $forum_ids ), '%d' ) );
    384                         $values             = array_merge( array( bbp_get_topic_tag_tax_id(), bbp_get_topic_post_type() ), $statuses, $forum_ids, $forum_ids, $forum_ids );
     389                        $values             = array_merge( array( bbp_get_topic_tag_tax_id(), bbp_get_topic_post_type() ), $statuses, $forum_ids );
    385390                        $query              = "SELECT DISTINCT tt.term_id
    386391                                FROM {$bbp_db->term_taxonomy} AS tt
    … …  
    390395                                WHERE tt.taxonomy = %s AND p.post_type = %s AND p.post_status IN ({$placeholders})
    391396                                        AND p.post_parent IN ({$forum_placeholders})
    392                                         AND CAST( fm.meta_value AS UNSIGNED ) IN ({$forum_placeholders})
    393                                         AND NOT EXISTS (
    394                                                 SELECT 1 FROM {$bbp_db->postmeta} AS excluded_fm
    395                                                 WHERE excluded_fm.post_id = p.ID AND excluded_fm.meta_key = '_bbp_forum_id'
    396                                                 AND CAST( excluded_fm.meta_value AS UNSIGNED ) NOT IN ({$forum_placeholders})
    397                                         )";
     397                                        AND CAST( fm.meta_value AS UNSIGNED ) = p.post_parent";
    398398                        $term_ids = $bbp_db->get_col( $bbp_db->prepare( $query, $values ) );
    399399
Note: See TracChangeset for help on using the changeset viewer.