[wp-trac] [WordPress Trac] #58962: Provide a way to load multiple specific options with a single database request

WordPress Trac noreply at wordpress.org
Wed Aug 2 21:50:50 UTC 2023


#58962: Provide a way to load multiple specific options with a single database
request
--------------------------------+----------------------
 Reporter:  flixos90            |      Owner:  flixos90
     Type:  enhancement         |     Status:  assigned
 Priority:  normal              |  Milestone:  6.4
Component:  Options, Meta APIs  |    Version:
 Severity:  normal              |   Keywords:
  Focuses:  performance         |
--------------------------------+----------------------
 WordPress's `get_option()` function generally relies on making individual
 database requests for each option, however with the majority of options
 (in most cases) being autoloaded, i.e. fetched once with a single database
 request and then stored in (memory) cache.

 The option autoloading approach has been helpful overall in minimizing
 database requests, however for many sites "excessive autoloading" (i.e.
 autoloading too many options) has led to problems, where lots of options
 are loaded in the frontend that are never used during these pageloads,
 which slows down load time performance. Sometimes the issue is even worse
 to the degree that certain object cache solutions cannot store the large
 amount of data anymore, which can lead to extremely slow performance due
 to the bug.

 Part of the problem is lack of documentation around option autoloading,
 its implications and best practices. For example, options that are only
 used in very specific contexts, e.g. a specific WP Admin screen, should
 preferably not be autoloaded. Though as of today, while preferable from an
 overall performance perspective, there is a lack of alternatives for use-
 cases where multiple options are still needed: For example, if a plugin
 needs to load 5-10 options on their own WP Admin screen, simply
 recommending to not autoload them would lead to 5-10 database requests on
 that WP Admin screen, i.e. unnecessarily slowing down performance of that
 screen.

 Therefore this ticket aims to provide a way to load (or prime in cache)
 multiple specific options with a single database request. This can be used
 as a reasonable alternative for use-cases like the above, encouraging to
 not use general option autoloading as a bandaid for the lack of another
 efficient way to load multiple options.

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


More information about the wp-trac mailing list