Make WordPress Core


Ignore:
Timestamp:
03/29/2023 10:18:34 AM (23 months ago)
Author:
spacedmonkey
Message:

Comments: Use wp_cache_get_multiple in WP_Comment_Query.

In the fill_descendants method in WP_Comment_Query, there is a loop the calls wp_cache_get to get child comments. Instead of getting one key at a time, use wp_cache_get_multiple` and get all keys at once.

Props spacedmonkey, tillkruess, mukesh27.
Fixes #57803.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-comment-query.php

    r55559 r55607  
    10311031            $uncached_parent_ids = array();
    10321032            $_parent_ids         = $levels[ $level ];
    1033             foreach ( $_parent_ids as $parent_id ) {
    1034                 $cache_key        = "get_comment_child_ids:$parent_id:$key:$last_changed";
    1035                 $parent_child_ids = wp_cache_get( $cache_key, 'comment-queries' );
    1036                 if ( false !== $parent_child_ids ) {
    1037                     $child_ids = array_merge( $child_ids, $parent_child_ids );
    1038                 } else {
    1039                     $uncached_parent_ids[] = $parent_id;
     1033            if ( $_parent_ids ) {
     1034                $cache_keys = array();
     1035                foreach ( $_parent_ids as $parent_id ) {
     1036                    $cache_keys[ $parent_id ] = "get_comment_child_ids:$parent_id:$key:$last_changed";
     1037                }
     1038                $cache_data = wp_cache_get_multiple( array_values( $cache_keys ), 'comment-queries' );
     1039                foreach ( $_parent_ids as $parent_id ) {
     1040                    $parent_child_ids = $cache_data[ $cache_keys[ $parent_id ] ];
     1041                    if ( false !== $parent_child_ids ) {
     1042                        $child_ids = array_merge( $child_ids, $parent_child_ids );
     1043                    } else {
     1044                        $uncached_parent_ids[] = $parent_id;
     1045                    }
    10401046                }
    10411047            }
Note: See TracChangeset for help on using the changeset viewer.