Make WordPress Core


Ignore:
Timestamp:
03/29/2023 10:48:34 AM (3 years ago)
Author:
spacedmonkey
Message:

Options, Meta APIs: Improve the lazy loading meta API to include current object id.

The existing lazy loading meta api, creates a queue of ids, to be primed, if the get_comment_meta or get_term_meta functions are called. However, it did not check to see if the requested id was in the queue, before prime all the ids in the queue. Now, it adds the id to the queue, is not already in the queue, saving a cache lookup / database query.

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/query/lazyLoadTermMeta.php

    r55252 r55608  
    109109        }
    110110
     111
     112        /**
     113         * @ticket 57901
     114         *
     115         * @covers ::wp_queue_posts_for_term_meta_lazyload
     116         */
     117        public function test_wp_queue_posts_for_term_meta_lazyload_insert_term() {
     118                $filter = new MockAction();
     119                add_filter( 'update_term_metadata_cache', array( $filter, 'filter' ), 10, 2 );
     120
     121                register_taxonomy( 'wptests_tax', 'post' );
     122
     123                $t1      = wp_insert_term( 'Foo', 'wptests_tax' );
     124                $term_id = $t1['term_id'];
     125
     126                new WP_Query(
     127                        array(
     128                                'post__in'            => self::$post_ids,
     129                                'lazy_load_term_meta' => true,
     130                        )
     131                );
     132
     133                get_term_meta( $term_id );
     134
     135                $args     = $filter->get_args();
     136                $first    = reset( $args );
     137                $term_ids = end( $first );
     138                $this->assertContains( $term_id, $term_ids );
     139        }
     140
    111141        /**
    112142         * @ticket 57150
     
    134164                $first    = reset( $args );
    135165                $term_ids = end( $first );
    136                 $this->assertNotContains( $remove_term_id, $term_ids );
     166                $this->assertContains( $remove_term_id, $term_ids );
    137167        }
    138168}
Note: See TracChangeset for help on using the changeset viewer.