Make WordPress Core


Ignore:
Timestamp:
10/30/2023 11:21:03 PM (14 months ago)
Author:
peterwilsoncc
Message:

Options, Meta APIs: Fast follow fixes for option cache priming functions.

A collection of fixes for wp_prime_option_caches():

  • cache arrays and objects in their serialized form for consistency with get_option() and wp_load_alloptions()
  • prevent repeat database queries for falsey and known non-existent options (notoptions)

Additional tests for wp_prime_option_caches() to ensure:

  • additional database queries are not made repriming options (known, known-unknown and alloptions)
  • cache is primed consistently
  • get_option() returns a consistent value regardless of how it is primed
  • database queries do not contain earlier primed options
  • get_option does not prime the cache when testing the cache has been successfully primed

Fixes a test for wp_prime_option_caches_by_group() to ensure get_option does not prime the cache when testing the cache has been successfully primed.

Follow up to [56445],[56990],[57013].

Reviewed by flixos90, hellofromTonya, joemcgill.
Merges [57029] to the 6.4 branch.

Props peterwilsoncc, costdev, flixos90, hellofromTonya, mikeschroder, joemcgill.
Fixes #59738. See #58962.

Location:
branches/6.4
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/6.4

  • branches/6.4/tests/phpunit/tests/option/wpPrimeOptionCachesByGroup.php

    r57016 r57030  
    4848        wp_prime_option_caches_by_group( 'group1' );
    4949
    50         // Check that options are now in the cache.
    51         $this->assertSame( get_option( 'option1' ), wp_cache_get( 'option1', 'options' ), 'option1\'s cache was not primed.' );
    52         $this->assertSame( get_option( 'option2' ), wp_cache_get( 'option2', 'options' ), 'option2\'s cache was not primed.' );
     50        /*
     51         * Check that options are now in the cache.
     52         *
     53         * Repeat the string here rather than using get_option as get_option
     54         * will prime the cache before the call to wp_cache_get if the option
     55         * is not in the cache. Thus causing the tests to pass when they should
     56         * fail.
     57         */
     58        $this->assertSame( 'value_option1', wp_cache_get( 'option1', 'options' ), 'option1\'s cache was not primed.' );
     59        $this->assertSame( 'value_option2', wp_cache_get( 'option2', 'options' ), 'option2\'s cache was not primed.' );
    5360
    5461        // Make sure option3 is still not in cache.
Note: See TracChangeset for help on using the changeset viewer.