Make WordPress Core

Opened 8 months ago

Last modified 8 months ago

#51117 accepted defect (bug)

Sitemap & XSL requests execute main query for home page.

Reported by: peterwilsoncc Owned by: pbiron
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.5
Component: Sitemaps Keywords:
Focuses: performance Cc:

Description (last modified by SergeyBiryukov)

When requesting a sitemap, the main query is run with the parameters for the is_home() request by default. The same is true for the stylesheet.

  • On a site without posts this can return a false 404 error for the sitemap
  • On a site without a persistent cache, this can result in 10 unneeded database queries.

Database log for requesting the first page of the posts sitemap is attached, other sitemap requests look similar up until the sitemap specific DB query is reached,


  • Prevent main query on sitemaps
  • Move stylesheet to a hard coded xsl file if possible

Attachments (1)

sitemaps.log (9.7 KB) - added by peterwilsoncc 8 months ago.

Download all attachments as: .zip

Change History (3)

#1 @SergeyBiryukov
8 months ago

  • Description modified (diff)
  • Summary changed from Sitemap & XLS requests execute main query for home page. to Sitemap & XSL requests execute main query for home page.

#2 @pbiron
8 months ago

  • Owner set to pbiron
  • Status changed from new to accepted

I've noticed this as well and thought "why is it bothering to run the main query when the results of that aren't used?".

But I'd point out that sitemaps aren't the only "rewrite rule-only" request that does this: https://example.com/robots.txt and https://example.com/feed run the main query as well.

While looking at this, I was happy to find that the REST API does not run the main query: it hooks into parse_request and short circuits the process when handling REST requests.

I haven't looked in detail yet, but am pretty sure sitemaps, robots.txt and feeds could do the same thing. I wonder whether it would be beneficial to introduce a general mechanism that all such "rewrite rule-only" requests could build on?

Note: See TracTickets for help on using tickets.