简体   繁体   English

Magento产品集合过滤

[英]Magento product collection filtering

Why hello there Magento gurus, 为什么在Magento大师那里问好,

I'm importing large product catalog in Magento, so every milisec counts. 我正在Magento中导入大型产品目录,因此每一个毫秒都至关重要。

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 导入已经完成,但是我现在正在寻找可以改进的部分,并发现了一个有趣的时刻(至少对我而言)-> http://screencast.com/t/Gq8VumQluKr

This is for 5K SKU's and as you can see, there is a big difference. 这是针对5K SKU's ,您可以看到,两者之间存在很大差异。

In second collection I used getData() and then from array fetched entity_id . 在第二个集合中,我使用了getData() ,然后从数组中获取了entity_id

But in first collection, I didn't use getData() and fetched ID from model function. 但是在第一个集合中,我没有使用getData()和从model函数中获取的ID。

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. 我知道getId()最有可能是对函数的调用,但是即使我调用了一些getLala()getData('lala') ,在集合上使用getData()然后进行循环也会快数百(甚至数千)倍。

My question is - why there is such difference in performance and how these methods differ? 我的问题是-为什么性能会有如此差异,这些方法又有何不同?

Thanks. 谢谢。

I believe your benchmarking code is incorrect. 我相信您的基准测试代码不正确。 You start benchmarking after getData() function call, but getData() is doing all the heavy lifting. 您可以在调用getData()函数后开始进行基准测试,但是getData()会承担所有繁重的工作。 You should start taking time before getData() function call. 您应该在调用getData()函数之前花些时间。 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. 当在不带getData的for循环中使用产品集合时,Magento内部将使用ArrayIterator遍历产品列表。 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将在内部调用getData函数(请检查lib / Varien / Data / Collection / DB.php中的load()函数)(如果尚未调用)。

Magento is designed to lazily load the product list only when you request it. Magento旨在仅在您请求时延迟加载产品列表。 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. 如果在集合上调用getData()函数,则请求产品列表并在那时收集它,或者如果使用for循环,则它将在循环之前请求产品列表。

getId() and $product['entity_id'] do not differ much, internally it is doing almost the same thing. getId()和$ product ['entity_id']差别不大,在内部它几乎在做同样的事情。 Product is Varien Object that implements ArrayAccess, so you can call $product['id'] as well as getId(), that both call getData('id') function internally. 产品是实现ArrayAccess的Varien对象,因此您可以调用$ product ['id']和getId(),两者都在内部调用getData('id')函数。 I believe there was a slight difference between 'id' and 'entity_id', but I'm not sure about that. 我相信'id'和'entity_id'之间存在细微的差别,但是我不确定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM