Make WordPress Core


Ignore:
Timestamp:
05/11/2023 12:25:51 PM (10 months ago)
Author:
spacedmonkey
Message:

Comments: Always lazily load comment meta.

In [34270] introduced lazy loading of comment meta. However, this was only in the context of WP_Query. Other parts of the codebase, like WP_Comment_Query did not lazily load comment meta. In this change, calls to update_meta_cache are now replaced with wp_lazyload_comment_meta, that instead of priming comment meta caches, just adds them to the queue to be primed it ever called. This results in far less database queries, as there a number of places where comment meta is being primed unnecessarily and never used. Adding everything to the comment meta queue, also means that if comment meta is used, that is all loaded in a single database / cache call.

Follow on from [55671], [55747].

Props spacedmonkey, peterwilsoncc, flixos90, mukesh27.
Fixes #57801.

File:
1 edited

Legend:

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

    r55660 r55749  
    14411441
    14421442    $comment_args = array(
    1443         'orderby'                   => 'comment_date_gmt',
    1444         'order'                     => 'ASC',
    1445         'status'                    => 'approve',
    1446         'post_id'                   => $post->ID,
    1447         'no_found_rows'             => false,
    1448         'update_comment_meta_cache' => false, // We lazy-load comment meta for performance.
     1443        'orderby'       => 'comment_date_gmt',
     1444        'order'         => 'ASC',
     1445        'status'        => 'approve',
     1446        'post_id'       => $post->ID,
     1447        'no_found_rows' => false,
    14491448    );
    14501449
     
    23802379        $parsed_args['reverse_top_level'] = ( 'desc' === get_option( 'comment_order' ) );
    23812380    }
    2382 
    2383     wp_queue_comments_for_comment_meta_lazyload( $_comments );
    23842381
    23852382    if ( empty( $parsed_args['walker'] ) ) {
Note: See TracChangeset for help on using the changeset viewer.