[wp-trac] [WordPress Trac] #54844: Unnecessary database queries when a block theme isn't in use

WordPress Trac noreply at wordpress.org
Mon Jan 17 12:51:17 UTC 2022


#54844: Unnecessary database queries when a block theme isn't in use
-----------------------------------+----------------------------
 Reporter:  johnbillion            |      Owner:  (none)
     Type:  defect (bug)           |     Status:  new
 Priority:  normal                 |  Milestone:  Future Release
Component:  Query                  |    Version:  5.8
 Severity:  normal                 |   Keywords:  needs-patch
  Focuses:  template, performance  |
-----------------------------------+----------------------------
 When a standard theme is in use (not a block theme) database queries to
 fetch `wp_template` post types are still performed by
 `get_block_templates()` even though there will be no templates associated
 with a non-block theme. These queries are unnecessary and should be
 avoided.

 Steps to reproduce:

 * Switch to the Twenty Twenty-One theme, which is not a block theme
 * Visit the home page
 * Using a debugging tool such as Query Monitor, observe that several
 database queries for `wp_template` post types are performed
 * As the theme is not a block template, observe that the queries all
 contain a `AND ( 0 = 1 )` clause because there are no `wp_theme` terms for
 the theme

 Introduced in 5.8.

 The cause is the unconditional call to `locate_block_template()` inside
 `get_query_template()` (which ultimately calls `get_block_templates()`).
 This function should only be called if the theme is a block theme.

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


More information about the wp-trac mailing list