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/class-wp-comment-query.php

    r55607 r55749  
    482482        $comment_ids = array_map( 'intval', $comment_ids );
    483483
     484        if ( $this->query_vars['update_comment_meta_cache'] ) {
     485            wp_lazyload_comment_meta( $comment_ids );
     486        }
     487
    484488        if ( 'ids' === $this->query_vars['fields'] ) {
    485489            $this->comments = $comment_ids;
     
    487491        }
    488492
    489         _prime_comment_caches( $comment_ids, $this->query_vars['update_comment_meta_cache'] );
     493        _prime_comment_caches( $comment_ids, false );
    490494
    491495        // Fetch full comment objects from the primed cache.
Note: See TracChangeset for help on using the changeset viewer.