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.

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

报告相同问题?

悬赏问题

  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算