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

WordPress Trac noreply at wordpress.org
Wed Oct 25 23:49:16 UTC 2023


#59738: `wp_load_options()` makes DB queries for known non-existent options
(notoptions).
--------------------------------+--------------------------------------
 Reporter:  peterwilsoncc       |      Owner:  (none)
     Type:  defect (bug)        |     Status:  new
 Priority:  normal              |  Milestone:  Awaiting Review
Component:  Options, Meta APIs  |    Version:
 Severity:  normal              |   Keywords:  has-patch has-unit-tests
  Focuses:  performance         |
--------------------------------+--------------------------------------
 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.

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


More information about the wp-trac mailing list