douhuan2101 2014-07-28 07:41
浏览 24
已采纳

Magento产品系列过滤

Why hello there Magento gurus,

I'm importing large product catalog in Magento, so every milisec counts.

Import is kind of done, but I'm now searching for parts that could be improved and found one interesting ( at least for me ) moment -> http://screencast.com/t/Gq8VumQluKr

This is for 5K SKU's and as you can see, there is a big difference.

In second collection I used getData() and then from array fetched entity_id.

But in first collection, I didn't use getData() and fetched ID from model function.

I know that getId() most likely is call to function, but even if I call some getLala() or getData('lala'), using getData() on collection and then looping will be hundreds ( or even thousands ) of times faster.

My question is - why there is such difference in performance and how these methods differ?

Thanks.

  • 写回答

1条回答 默认 最新

  • duanemei2194 2014-07-29 08:31
    关注

    I believe your benchmarking code is incorrect. You start benchmarking after getData() function call, but getData() is doing all the heavy lifting. You should start taking time before getData() function call. I will explain it in more detail:

    When you use product collection in for loop without getData, Magento internally will use ArrayIterator, to iterate over product list. And to get that list, Magento will call getData function internally (check out load() function in lib/Varien/Data/Collection/DB.php) if it's not already called.

    Magento is designed to lazily load the product list only when you request it. If you call getData() function on collection, you request the product list and it gets collected at that time, or if you use for loop, then it will request the product list before the loop.

    getId() and $product['entity_id'] do not differ much, internally it is doing almost the same thing. Product is Varien Object that implements ArrayAccess, so you can call $product['id'] as well as getId(), that both call getData('id') function internally. I believe there was a slight difference between 'id' and 'entity_id', but I'm not sure about that.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么