vendidero / woocommerce-germanized

Adapt WooCommerce to the German Market with Germanized for WooCommerce
https://vendidero.de/woocommerce-germanized
Other
51 stars 41 forks source link

Account for `-1` being returned by `wc_get_page_id()` #173

Closed johnbillion closed 2 years ago

johnbillion commented 2 years ago

I've identified a large number of unnecessary database queries being triggered by WooCommerce Germanized, and I traced the problem to the fact that the WooCommerce function wc_get_page_id() can return -1 if a given page does not exist. Germanized doesn't check for this and the result is that if some pages are not configured, for example the "Terms & Conditions" page, Germanized ultimately causes the following database query to be called repeatedly:

SELECT *
FROM wp_posts
WHERE ID = -1
LIMIT 1

This is because wc_gzd_get_page_permalink() does not expect wc_get_page_id() to return -1 and therefore passes it through to get_permalink() which will perform a database query looking for a post with an ID of -1.

Impact

On this particular client site we're seeing this unnecessary query being performed over 25 times on every page load.

To reproduce

Results will probably differ on different sites and with a different number of pages either configured or not configured.

Screenshot

dennisnissle commented 2 years ago

Hi @johnbillion,

thanks for the patch and the research, seems fine. I'll merge it.

Best, Dennis