加载属性值而不加载整个实体
因此,我正在编写一个功能,其中我获取类别的父类别 id,并希望获取 Magento 中其中一个父类别的 url_key。我想在不加载类别的情况下执行此操作,并找到了此方法getAttributeRawValue
,可以在此处找到/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4 /Abstract.php
。基本上,似乎没有必要加载整个实体,然后只获取与该实体 ID 关联的属性值。
它为我提供了我需要的东西,但我想知道它是否比加载类别和获取属性要好得多。加载类别本质上是做同样的事情,但对每个属性都做同样的事情吗?
So I was writing a piece of functionality where I was getting the parent category ids of a category and wanted to get the url_key of one of the parents in Magento. I wanted to do this without having to load the category and found this method getAttributeRawValue
, which can be found here /app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Abstract.php
. Basically it seems unnecessary to load a whole entity then to just get the attribute value associated to that entity id.
It gets me what I need, but I am wondering if it is all that much better then loading the category and getting the attribute. Is loading the category essentially doing the same thing but doing it for every attribute?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的第一个想法是使用内置的 Varien Profiler 对其进行定量测试。这是一个非常有用的技巧,但没有得到充分利用。
基本上,您需要在管理中打开分析(系统>配置>高级>开发人员>调试>分析器),然后在要分析的代码的两侧插入带有唯一字符串的启动/停止指令。例如,
在浏览器中加载该页面,您将在底部看到分析器输出。
享受!
My first thought would be to use the inbuilt Varien Profiler to test it quantitatively. It's an underutilized by very useful trick.
Basically, you need to turn on Profiling in the Admin (System>Config>Advanced>Developer>Debug>Profiler) and then insert the start/stop instructions with a unique string either side of the code that you want to profile. e.g.
Load the page in your browser and you will see the Profiler output at the base.
Enjoy!