A bunch to unpack there, which I’m appreciative of. Let me give it a shot…
Rules only auto-flush when you visit the permalinks settings screen. There shouldn’t be WC elements on the permalinks screen if it’s deactivated.
I agree with you on this. Even when I was disabling WC, I always enabled it on /wp-admin/ requests, so it would always be present on the Permalinks screen.
The only other time a flush happens is when code calls for it. It’s not unheard of for plugins or themes to inappropriately call for flushing when it’s not needed.
I think this is getting at the crux of my question, and (unfortunately) means there’s no way for me to know / there’s not a specific page request that causes the flusing/rewriting. Rather, it’s some other plugin that’s calling flush_rewrite_rules() as part of some general page/post/tax request, resulting in the rules being regenerated when WC is not active.
I took a quick look through all the source for all the plugins and it is shocking to me how often/many times flush_rewrite_rules() is called. I wouldn’t have thought it necessary to flush those rules so often, but perhaps it is! (I don’t pretend to be an expert on permalinks/rewrites – not by a long shot!)
The redirect for product URLs when WC is deactivated is due to the lack of registered post types. The rewrite rules exist (because the rules do persist) and attempt to initiate a query for the related product, but the parser at that moment knows of no post type “product”, so it triggers the redirect.
This is the interesting bit. What I was *hoping* would be the case (and is the case for ~half a day at a time until the persisted rewrite rules are regenerated) is that the (persisted) rewrite rules would initiate a query for the related product, which would then cause WC to be loaded on the product page (and other WC pages like /cart, etc. which were whitelisted to run the plugin. The endless redirect only happens when the persisted rewrite rules have been regenerated (at a time when WC wasn’t active) to not have all the /product* rewrite rules present. Then, other “fallback” rules kick in and continue to redirect until the browser bails.
I hope that the paragraph above also answers this following point you made, but perhaps I’m still missing something?
What I’m not understanding is, if one makes a product URL request, thus causing WC to be reactivated, why would that request get redirected? It seems like WC isn’t getting auto-activated like you think it does. Otherwise the post types and taxonomies would be registered and the URLs would work, right?
Onto more caching…
you could at least set appropriate caching headers for client side caching (you may already do so) on certain pages so people only need to endure a longer load time once per page. It’ll at least benefit return visitors.
I do already have client side headers set, but unfortunately I have very few (single digit percent?) return visitors to any given page that would be cached – my site is a series of stories that folks tend to read, and then are done with that story. I like the thought process though, thank you!
Also, just to share – not that it matters all that much – when WC is enabled, I see about a 4-7 second increase to any (uncached) page generation, which is why I’m looking to make some sort of optimization. And, I’m running this on what is a severely underpowered/unoptimized system (in Azure) because… well, mostly because I’m both cheap and have a propensity to MS infrastructure given my work life.
I really do appreciate your time/responses here. Even if I’m not able to do what I wanted to do, it does help me to (slightly) better understand the situation and other ways to address it.