Make WordPress Core


Ignore:
Timestamp:
09/14/2023 12:38:04 PM (17 months ago)
Author:
spacedmonkey
Message:

Taxonomy: Introduce 'cache_results' parameter to WP_Term_Query for bypassing query caching.

Incorporating a new 'cache_results' parameter into the WP_Term_Query class, this commit empowers developers with the ability to bypass query caches, explicitly triggering database queries when needed. This brings the WP_Term_Query class inline with WP_Query and WP_User_Query that already have a 'cache_results' parameter.

Update the term_exists function to use this new parameter, so the term query caches are not used while importing.

Props dlh, spacedmonkey, peterwilsoncc.
Fixes #52710.

File:
1 edited

Legend:

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

    r56548 r56585  
    30273027
    30283028    /**
     3029     * @ticket 52710
     3030     */
     3031    public function test_get_terms_without_update_get_terms_cache() {
     3032        $this->set_up_three_posts_and_tags();
     3033
     3034        $num_queries = get_num_queries();
     3035
     3036        // last_changed and num_queries should bump.
     3037        $terms = get_terms(
     3038            'post_tag',
     3039            array(
     3040                'cache_results'          => false,
     3041                'update_term_meta_cache' => false,
     3042            )
     3043        );
     3044        $this->assertCount( 3, $terms, 'After running get_terms, 3 terms should be returned' );
     3045        $this->assertSame( $num_queries + 2, get_num_queries(), 'There should be only 2 queries run, only term query and priming terms' );
     3046
     3047        $num_queries = get_num_queries();
     3048
     3049        // last_changed and num_queries should bump again.
     3050        $terms = get_terms(
     3051            'post_tag',
     3052            array(
     3053                'cache_results'          => false,
     3054                'update_term_meta_cache' => false,
     3055            )
     3056        );
     3057        $this->assertCount( 3, $terms, 'After running get_terms for a second time, 3 terms should be returned' );
     3058        $this->assertSame( $num_queries + 1, get_num_queries(), 'On the second run, only run the term query, priming terms happens on the first run' );
     3059    }
     3060
     3061    /**
    30293062     * @ticket 35935
    30303063     */
Note: See TracChangeset for help on using the changeset viewer.