[wp-trac] [WordPress Trac] #59738: `wp_prime_option_caches()` makes DB queries for known non-existent options (notoptions). (was: `wp_load_options()` makes DB queries for known non-existent options (notoptions).)

WordPress Trac noreply at wordpress.org
Fri Oct 27 01:09:25 UTC 2023


#59738: `wp_prime_option_caches()` makes DB queries for known non-existent options
(notoptions).
--------------------------------------+--------------------------
 Reporter:  peterwilsoncc             |       Owner:  flixos90
     Type:  defect (bug)              |      Status:  reviewing
 Priority:  normal                    |   Milestone:  6.4
Component:  Options, Meta APIs        |     Version:
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:  performance
--------------------------------------+--------------------------
Description changed by peterwilsoncc:

Old description:

> The function `wp_load_options()` is intended to reduce the number of
> database queries by allowing the caching of options in bulk.
>
> When determining which options to query for, it doesn't check the
> `notoptions` cache so re-queries the database for options that are known
> not to exist.
>
> To reproduce in `wp shell`
>

> {{{
> wp> get_option( 'nonexistent_option' );
> => bool(false)
> $initial_num_queries = get_num_queries();
> => int(10) ### Will differ depending on set up
> wp> wp_load_options( array( 'nonexistent_option' ) );
> => NULL
> wp> get_num_queries() - $initial_num_queries;
> => int(1)
> }}}
>
> A diff is incoming that resolves the issue, to avoid unnecessary requests
> to the cache, it checks the options cache and bails early if the
> requested options are all primed.
>
> If items appear to need priming after that, the notoptions cache is
> checked and known invalid options are removed. If no options need to be
> primed after that then the function returns early.
>
> As the likelihood of multiple requests to prime non-existent options is
> fairly low, I don't think this needs to be fixed in a rush and can be
> handled in 6.4.1 or 6.5.

New description:

 The function `wp_prime_option_caches()` is intended to reduce the number
 of database queries by allowing the caching of options in bulk.

 When determining which options to query for, it doesn't check the
 `notoptions` cache so re-queries the database for options that are known
 not to exist.

 To reproduce in `wp shell`


 {{{
 wp> get_option( 'nonexistent_option' );
 => bool(false)
 $initial_num_queries = get_num_queries();
 => int(10) ### Will differ depending on set up
 wp> wp_prime_option_caches( array( 'nonexistent_option' ) );
 => NULL
 wp> get_num_queries() - $initial_num_queries;
 => int(1)
 }}}

 A diff is incoming that resolves the issue, to avoid unnecessary requests
 to the cache, it checks the options cache and bails early if the requested
 options are all primed.

 If items appear to need priming after that, the notoptions cache is
 checked and known invalid options are removed. If no options need to be
 primed after that then the function returns early.

 As the likelihood of multiple requests to prime non-existent options is
 fairly low, I don't think this needs to be fixed in a rush and can be
 handled in 6.4.1 or 6.5.

--

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/59738#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list