Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Experimental tracking support data for impressions causing slowdown #4695

Closed
notdian opened this issue Sep 8, 2021 · 7 comments · Fixed by #5002
Closed

Experimental tracking support data for impressions causing slowdown #4695

notdian opened this issue Sep 8, 2021 · 7 comments · Fixed by #5002
Assignees
Labels
focus: performance The issue/PR is related to performance. type: bug The issue/PR concerns a confirmed bug.

Comments

@notdian
Copy link

notdian commented Sep 8, 2021

Product grid appends inject item data to body, this line is not cached at all, when you have multiple product grids (in my case 7 * 12 ) causes over extra un cachable queries.

@notdian notdian added the type: bug The issue/PR concerns a confirmed bug. label Sep 8, 2021
@notdian notdian changed the title Experimental tracking support data for impression causing slowdown Experimental tracking support data for impressions causing slowdown Sep 8, 2021
@nielslange
Copy link
Member

Hello @dianfishekqi 👋

Thanks for reporting this issue. Can you provide detailed steps on how to reproduce and monitor the problem that you reported?

@nerrad
Copy link
Contributor

nerrad commented Sep 23, 2021

While we'd appreciate more details about the exact problems you are encountering here @dianfishekqi I've taken a brief look at the code path referred to and here's a synopsis. The code being referenced is here:

https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/e00cd017bfd3d30167a9821db5725675a58478f1/src/BlockTypes/AbstractProductGrid.php#L93

While the $products being mapped to the function Automattic\WooCommerce\Blocks\StoreApi\Schemas::get_item_response ARE in fact cached:

https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/e00cd017bfd3d30167a9821db5725675a58478f1/src/BlockTypes/AbstractProductGrid.php#L292-L308

It looks like that each call to Automattic\WooCommerce\Blocks\StoreApi\Schemas::get_item_response results in additional queries for data related to the products (eg get_the_terms). Although it appears that those could be cached as well, so at least the initial query to terms for a given product ID should be the only query made if that product appears in multiple instances of the block.

https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/e00cd017bfd3d30167a9821db5725675a58478f1/src/StoreApi/Schemas/ProductSchema.php#L430-L466

@mikejolley, without having any further data around exactly what the issue author is referring to here, do you think it's worthwhile at least auditing the queries happening through this code stack and seeing if we can optimize more as a potential performance improvement (and add to the backlog)?

@notdian
Copy link
Author

notdian commented Sep 23, 2021

Hello all,

SELECT post_id as variation_id, meta_key as attribute_key, meta_value as attribute_value FROM wp_postmeta WHERE post_id IN (25295,25298,25300,25303)AND meta_key IN ('attribute_pa_size') |

one of the queries not being cached debugged on Query Monitor source Automattic\W\B\S\S\ProductSchema>get_variations()

@nerrad nerrad added focus: performance The issue/PR is related to performance. and removed needs feedback labels Oct 14, 2021
@notdian
Copy link
Author

notdian commented Oct 25, 2021

@nerrad It's amounting to 91/121 queries on our homepages.

Screen Shot 2021-10-25 at 10 31 59

Screen Shot 2021-10-25 at 10 34 08

@notdian
Copy link
Author

notdian commented Oct 25, 2021

Commenting it out :
Screen Shot 2021-10-25 at 10 36 26

Brings down the number of queries to zero improving page generation time by 70%.

Screen Shot 2021-10-25 at 10 37 46

@nerrad
Copy link
Contributor

nerrad commented Oct 25, 2021

Thanks! This is something on the list of things we'll look into.

@mikejolley mikejolley self-assigned this Oct 26, 2021
@mikejolley
Copy link
Member

mikejolley commented Oct 26, 2021

There is no evidence that the queries are uncached (which would be reported as duplicate queries in Query Monitor), there are just many similar queries per variable product. We can look at priming them somehow, or revise what is exposed via the experimental action.

Managed to replicate the query issue with multiple duplicate blocks.

mikejolley added a commit that referenced this issue Nov 4, 2021
* Cache variation_meta_data to prevent duplicate queries with multiple grids

* Prime the cache

* Improve existing cache detection

* Expand comment
jonny-bull pushed a commit to jonny-bull/woocommerce-gutenberg-products-block that referenced this issue Dec 14, 2021
…5002)

* Cache variation_meta_data to prevent duplicate queries with multiple grids

* Prime the cache

* Improve existing cache detection

* Expand comment
jonny-bull pushed a commit to jonny-bull/woocommerce-gutenberg-products-block that referenced this issue Dec 16, 2021
…5002)

* Cache variation_meta_data to prevent duplicate queries with multiple grids

* Prime the cache

* Improve existing cache detection

* Expand comment
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
focus: performance The issue/PR is related to performance. type: bug The issue/PR concerns a confirmed bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants