Make WordPress Core


Ignore:
Timestamp:
05/11/2023 12:25:51 PM (15 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-query.php

    r55703 r55749  
    28142814                wp_cache_add( $cache_key, $comment_ids, 'comment-queries' );
    28152815            }
    2816             _prime_comment_caches( $comment_ids, false );
     2816            _prime_comment_caches( $comment_ids );
    28172817
    28182818            // Convert to WP_Comment.
     
    33733373                wp_cache_add( $comment_cache_key, $comment_ids, 'comment-queries' );
    33743374            }
    3375             _prime_comment_caches( $comment_ids, false );
     3375            _prime_comment_caches( $comment_ids );
    33763376
    33773377            // Convert to WP_Comment.
     
    34883488        }
    34893489
    3490         // If comments have been fetched as part of the query, make sure comment meta lazy-loading is set up.
    3491         if ( ! empty( $this->comments ) ) {
    3492             wp_queue_comments_for_comment_meta_lazyload( $this->comments );
    3493         }
    3494 
    34953490        if ( ! $q['suppress_filters'] ) {
    34963491            /**
Note: See TracChangeset for help on using the changeset viewer.