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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀