Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance problem in WPSEO_Sitemaps::get_last_modified_gmt #21276

Open
icurdinj opened this issue Mar 28, 2024 · 1 comment
Open

Performance problem in WPSEO_Sitemaps::get_last_modified_gmt #21276

icurdinj opened this issue Mar 28, 2024 · 1 comment

Comments

@icurdinj
Copy link

Is your feature request related to a problem? Please describe.

On our sites with big databases, sitemap generation is a performance problem. We've located a possibility for significant improvement.

Short explanation: there is a method WPSEO_Sitemaps::get_last_modified_gmt(). It gets called a lot of times while sitemaps are generated, and triggers a heavy database query. It is cached internally, memoized. However, that cache gets invalidated several times during sitemap generation, and the method repeats exactly the same heavy database query several times.

This is the code block that invalidates the cache:

foreach ( $post_types as $post_type ) {
	if ( ! isset( $post_type_dates[ $post_type ] ) ) { // If we hadn't seen post type before. R.
		$post_type_dates = null;
		break;
	}
}

Here's the catch - invalidating the cache is based on the parameters that are not used in the query itself. So, it looks pointless to me - cache is invalidated, and then exactly the same query is triggered which produces exactly the same results which are put back into cache.

Simply deleting this cache invalidation part produces the same sitemap in about half the time. Huge performance improvement.

Describe the solution you'd like

Two possible things that would help us:

  1. Review this cache invalidation and, if I'm not missing something, it's pointless, and it could be removed or reworked.
  2. If option 1 is not an option, add a filter that we could hook into to turn this cache invalidation off for our sites.

Why do you think this feature is something we should consider for the Yoast SEO plugins?

It would probably help all sites with lots of content.

@josevarghese
Copy link
Contributor

Hi @icurdinj

Thanks for using the Yoast SEO plugin and for creating this issue. Our development team will look into the details shared over here and will get back to you.

Thanks for your patience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants