Make WordPress Core

Opened 19 months ago

Closed 19 months ago

Last modified 19 months ago

#56923 closed defect (bug) (fixed)

register_block_core_template_part does WP_Query even on themes that do not support it

Reported by: spacedmonkey's profile spacedmonkey Owned by: desrosj's profile desrosj
Milestone: 6.1.1 Priority: high
Severity: normal Version: 6.1
Component: Themes Keywords: close
Focuses: performance Cc:

Description (last modified by sabernhardt)

register_block_core_template_part functions calls, build_template_part_block_variations -> build_template_part_block_instance_variations ->
get_block_templates.

This calls WP_Query and gets ALL posts of post type wp_template_part. This happens on classic themes that do not even support theme parts.

Attachments (1)

Screenshot 2022-10-27 at 21.33.20.png (124.5 KB) - added by spacedmonkey 19 months ago.
Screenshot from 2017 theme.

Download all attachments as: .zip

Change History (15)

@spacedmonkey
19 months ago

Screenshot from 2017 theme.

#2 @sabernhardt
19 months ago

  • Description modified (diff)
  • Keywords has-patch added
  • Milestone changed from Awaiting Review to 6.1.1
  • Priority changed from normal to high

Someone from the release squad could move this to the 6.1 milestone, but I can put in the minor.

Adding that condition removes the extra query from Twenty Seventeen.

The build_template_part_block_instance_variations() function was introduced in r54257.

This ticket was mentioned in Slack in #core by jeffpaul. View the logs.


19 months ago

#4 @Cybr
19 months ago

This WP_Query is invoked before template_redirect, so template parts are requested before we even know what kind of template we're dealing with.

Succinctly, I expect filters pre_get_posts / the_posts not to be queried before action wp_loaded. I think this premature registration is harmful, not only because it now creates bugs (CPTs aren't registered before the first query happens), but it causes significant performance losses.

#5 @spacedmonkey
19 months ago

  • Keywords commit added

My PR #45362 has been merged. This patch needed to ported from gutenberg to core. CC @mamaduka

#6 @Mamaduka
19 months ago

There's no need for porting. PHP files from the block-library package are included during the build.

I just need to cherry-pick the changes.

#7 @peterwilsoncc
19 months ago

@Cybr Are you able to open a ticket to move register_block_core_template_part to run later in the bootstrapping process. Whether that's later on the init hook or moving it to another hook is best for a dedicated ticket.

#8 @Cybr
19 months ago

@peterwilsoncc I think registering stuff at init is fair. Though, I also think using WP Query before template_redirect isn't, let alone misusing the Post Types API et co for stuff that isn't a Post Type.

In that, I think wp_template's foundation should be rewritten without considering Post Types but instead something bespoke --- perhaps having a new database table if deemed necessary. I believe this issue (45601) is already looking into that, but without noting the severity or scope of the cause.

I'm confident the Post Type API eased the integration for storing and filtering, but it shouldn't be deemed a long-term strategy. Elementor's recklessness is still haunting me; please don't let Gutenberg catch up to them.

#9 @spacedmonkey
19 months ago

@Cybr @peterwilsoncc

The issue here, is that the WP_QUery is run on all requests, even when they are not needed. They are only needed in the site editor. I have created a ticket to fix this issue here. This involves loading the variants only when needed. This is a big change and is unlikely to make into a point release sadly.

#10 @desrosj
19 months ago

  • Keywords close added; commit removed
  • Version changed from trunk to 6.1

Marking this as close because the this will be fixed when the block-library package is updated prior to 6.1.1 RC later this week.

#11 @peterwilsoncc
19 months ago

  • Keywords has-patch removed

keyword managing to keep the workflow report nice.

This ticket was mentioned in Slack in #core by jeffpaul. View the logs.


19 months ago

#13 @desrosj
19 months ago

  • Owner set to desrosj
  • Resolution set to fixed
  • Status changed from new to closed

In 54811:

Editor: Update block editor packages to the latest patch releases.

This updates the block editor related npm dependencies to their latest patch versions ahead of WordPress 6.1.1.

For a full list of what’s included in this update, see https://github.com/WordPress/gutenberg/compare/432ed388f8d0614f9de775738b24b0ea96664715...6566f5fe9ece6ad5ae550349d3b1f0944a011040.

Props aaronrobertshaw, ntsekouras, bernhard-reiter, ramonopoly, isabel_brison, andrewserong, get_dave, scruffian, andraganescu, talldanwp, mciampini, noisysocks, cbravobernal, bph, tyxla, ellatrix, czapla, mcsf, ironprogrammer, wildworks, peterwilsoncc, mamaduka, mikachan, spacedmonkey, cybr, youknowriad, alexstine, aristath, kevin940726, ndiego, 0mirka00, poena, joen, ryankienstra, desrosj, vtad, nithins53, audrasjb, kacper3355, sabernhardt.
Fixes #57038, #56818, #56955, #56923.

#14 @desrosj
19 months ago

In 54812:

Editor: Update block editor packages to the latest patch releases.

This updates the block editor related npm dependencies to their latest patch versions ahead of WordPress 6.1.1.

For a full list of what’s included in this update, see https://github.com/WordPress/gutenberg/compare/432ed388f8d0614f9de775738b24b0ea96664715...6566f5fe9ece6ad5ae550349d3b1f0944a011040.

Props aaronrobertshaw, ntsekouras, bernhard-reiter, ramonopoly, isabel_brison, andrewserong, get_dave, scruffian, andraganescu, talldanwp, mciampini, noisysocks, cbravobernal, bph, tyxla, ellatrix, czapla, mcsf, ironprogrammer, wildworks, peterwilsoncc, mamaduka, mikachan, spacedmonkey, cybr, youknowriad, alexstine, aristath, kevin940726, ndiego, 0mirka00, poena, joen, ryankienstra, desrosj, vtad, nithins53, audrasjb, kacper3355, sabernhardt.
Merges [54811] to the 6.1 branch.
Fixes #57038, #56818, #56955, #56923.

Note: See TracTickets for help on using tickets.