klaviyo / magento2-klaviyo

37 stars 51 forks source link

Improve performance of Viewed Product block #254

Closed ihor-sviziev closed 1 year ago

ihor-sviziev commented 1 year ago

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

  1. Create product and link it to 150+ categories
  2. Enable Magento profiler with php bin/magento dev:profiler:enable and see how long klaviyo block is getting rendered.
  3. Apply the patch
  4. Compare results between the measurements

Pre-Submission Checklist:

NOTE: Please use the Changelogger cli tool to manage versioned file upgrades.

ihor-sviziev commented 1 year ago

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.