Make WordPress Core


Ignore:
Timestamp:
04/21/2023 09:22:04 AM (15 months ago)
Author:
spacedmonkey
Message:

Taxonomy: Always lazily load term meta.

In [34529] introduced lazy loading of term meta. However, this was only in the context of WP_Query. Other parts of the codebase, like WP_Term_Query did not lazily load term meta. In this change, calls to update_termmeta_cache are now replaced with wp_lazyload_term_meta, that instead of priming term 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 term meta is being primed unnecessarily and never used. Adding everything to the term meta queue, also means that if term meta is used, that is all loaded in a single database / cache call.

Props spacedmonkey, mukesh27, peterwilsoncc.
Fixes #57645.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/term/wpGetObjectTerms.php

    r53942 r55671  
    616616     * @ticket 10142
    617617     */
    618     public function test_termmeta_cache_should_be_primed_by_default() {
     618    public function test_termmeta_cache_should_be_lazy_loaded_by_default() {
    619619        global $wpdb;
    620620
     
    636636        }
    637637
    638         $this->assertSame( $num_queries, $wpdb->num_queries );
     638        $this->assertSame( $num_queries + 1, $wpdb->num_queries );
    639639    }
    640640
     
    701701        }
    702702
    703         $this->assertSame( $num_queries, $wpdb->num_queries );
     703        $this->assertSame( $num_queries + 1, $wpdb->num_queries );
    704704    }
    705705
     
    734734        }
    735735
    736         $this->assertSame( $num_queries, $wpdb->num_queries );
     736        $this->assertSame( $num_queries + 1, $wpdb->num_queries );
    737737    }
    738738
Note: See TracChangeset for help on using the changeset viewer.