woothemes/woocommerce — pull request #3849 by franticpsyx (2013-09-27 09:25:55+00:00)
Title: Add woocommerce_delete_product_transients action

Some background information:

When a shop page contains many variable items with a large number of variations, even a reasonably fast server may take a long time to render the page.

The same happens if a product bundle contains a few variable items with a large number of variations (>50). A client has a couple bundles, each containing multiple instances of the same variable product containing around 30 variations, each instance with different variation filtering settings.

I have traced the slowdown to function get_available_variations() and contemplated for a few seconds about the possibility of adding a transient there: If a transient is added there, the contained filters will only have effect in different calls of get_available_variations() only if a unique (filterable?) parameter is passed into get_available_variations() to modify the transient name depending on the scope. And of course properly delete all these when needed.

Instead of making any changes to the core, I have experimented with the idea of allowing the creation of get_available_variations() transients when the function is called inside a bundle, only in problematic cases, by adding a specific meta to the bundle product that enables this.

However, the created transients will need to be cleaned when i) the bundled variable product is altered, ii) the main bundle settings are altered, iii) all other cases that trigger a transient cleaning. Hence the need for a woocommerce_delete_product_transients action. When a post_id is passed to wc_delete_product_transients, this can also be done by hooking into the clean_post_cache action, but an action hook is necessary otherwise.

Thoughts/comments? Would it make sense to go all the way and think about unique-named transients for get_available_variations()?