I noticed that some product pages loaded pretty fast while others did not. I did profiling and noticed that Klaviyo Viewed Product block was loading about 0.26-0.3 seconds on my pretty fast machine, which is very big number. That was caused by loading all linked category models in the loop (some products have 150+ categories).
To improve this situation, I replaced the loading category model in the loop with using a single collection call with fetching only needed info (category name). That worked way faster on the same machine- about 0.007 vs 0.3 seconds.
Manual Testing Steps
Create product and link it to 150+ categories
Enable Magento profiler with php bin/magento dev:profiler:enable and see how long klaviyo block is getting rendered.
Apply the patch
Compare results between the measurements
Pre-Submission Checklist:
[ ] You've updated the CHANGELOG following the steps here
[ ] Internal Only - If this is a release, please confirm the following:
[ ] The links in the changelog have been updated to point towards the new versions
[ ] The version has been incremented in the following places: module.xml and composer.json
NOTE: Please use the Changelogger cli tool to manage versioned file upgrades.
I see a related PR https://github.com/klaviyo/magento2-klaviyo/pull/130, but it has a limit of 30 categories. I am wondering if that's expected. In comparison, my PR isn't adding any difference to the result.
Description
I noticed that some product pages loaded pretty fast while others did not. I did profiling and noticed that Klaviyo Viewed Product block was loading about 0.26-0.3 seconds on my pretty fast machine, which is very big number. That was caused by loading all linked category models in the loop (some products have 150+ categories). To improve this situation, I replaced the loading category model in the loop with using a single collection call with fetching only needed info (category name). That worked way faster on the same machine- about 0.007 vs 0.3 seconds.
Manual Testing Steps
php bin/magento dev:profiler:enable
and see how long klaviyo block is getting rendered.Pre-Submission Checklist:
NOTE: Please use the Changelogger cli tool to manage versioned file upgrades.