[英]codeIgniter Datamapper Performance on Joins with include_related
I'm using codeIgniter 2.1.4 with Datamapper and i worry about Datamapper performance. 我正在使用带有Datamapper的codeIgniter 2.1.4,我担心Datamapper的性能。
My results are only 2 rows and return successfully! 我的结果只有2行并且成功返回!
But when i dumped $posts
with var_dump($posts)
, I'm getting 20.000 code lines with included all data/relations/configs/tables/fields/languages etc.. 但是当我用
var_dump($posts)
转储$posts
时,我得到了20.000个代码行 ,包括所有数据/关系/配置/表/字段/语言等。
Sorry, I couldnt paste dumped data because of excessive lines. 抱歉,由于线路过多,我无法粘贴转储数据。
What's the problem? 有什么问题? Where am I doing wrong?
我哪里做错了?
Its my sample query: 我的样本查询:
$posts = new post_model();
$posts->where('active', 1)
->where('slug', $slug)
->include_related('users', '*', 'user', true)
->include_related('categories', '*', 'category', true)
->include_related('tags', '*', 'tag', true)
->include_related('groups', '*', 'group', true)
->get_paged($this->uri->segment(4), 50, TRUE);
Include Related Model Assignments: 包括相关模型分配:
public $has_one = array('users' =>
array(
'class' => 'users_m',
'other_field' => 'post',
'model_path' => 'application/modules/users',
),
'categories' => array(),
'tags' => array(),
'groups' => array(),
);
Posts Related Assignments: 帖子相关作业:
public $has_one = array(
'request' => array(
'class' => 'posts_m',
'model_path' => 'application/modules/posts',
)
);
I set instantiate
as false
and dumped data decreased to 3.000 lines.. I really didnt understand.. 我将
instantiate
设置为false
并将转储数据减少到3.000行..我真的不明白..
You aren't doing anything wrong -- this is just the way it is. 你没有做错任何事 - 这就是它的方式。
Try to understand how PHP, and CodeIgniter work.
尝试了解PHP和CodeIgniter的工作原理。
In PHP5, all objects are assigned by reference.
在PHP5中,所有对象都是通过引用分配的。 This means that although you see them when you access a Datamapper object, they are not copies, and don't take up memory.
这意味着虽然您在访问Datamapper对象时看到它们,但它们不是副本,也不占用内存。
CodeIgniter works by assigning all objects as singletons to $this, so a var_dump($this) will show you pages and pages of object information.
CodeIgniter的工作原理是将所有对象作为单例分配给$ this,因此var_dump($ this)将显示对象信息的页面和页面。 All other objects that access CI ( either via an automatic mechanism or through get_instance() ) use references.
访问CI的所有其他对象(通过自动机制或通过get_instance())使用引用。
So obviously you'll see all this when you dump a Datamapper object.
很明显,当你转储Datamapper对象时,你会看到所有这些。 Because Datamapper accesses the database, language, and form validation libraries, which in turn have links to several other libraries.
因为Datamapper访问数据库,语言和表单验证库,而这些库又链接到其他几个库。
http://ellislab.com/forums/viewthread/188420/#890508 http://ellislab.com/forums/viewthread/188420/#890508
$instantiate
- IfTRUE
, then actual objects are instantiated and populated with the columns automatically.$instantiate
- 如果为TRUE
,则实例化实例化对象并自动填充列。
http://datamapper.wanwizard.eu/pages/getadvanced.html http://datamapper.wanwizard.eu/pages/getadvanced.html
Instantiate TRUE
means more data. 实例化
TRUE
意味着更多数据。 Intantiate FALSE
means less data. 实例化
FALSE
意味着更少的数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.