codeIgniter Datamapper在与include_related连接时的性能


codeIgniter Datamapper Performance on Joins with include_related

我使用codeIgniter 2.1.4与Datamapper,我担心Datamapper的性能。

我的结果只有2行并成功返回!

但是当我用var_dump($posts)倾倒$posts时,我得到了 20,000行代码,包括所有数据/关系/配置/表/字段/语言等。

对不起,我不能粘贴转储的数据,因为太多的行。

有什么问题吗?我哪里做错了?

这是我的示例查询:

$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);

包括相关的模型分配:

public $has_one = array('users' => 
                                array(
                                  'class' => 'users_m',
                                  'other_field' => 'post',
                                  'model_path' => 'application/modules/users',
                                ),
                         'categories' => array(),
                         'tags'       => array(),
                         'groups'     => array(),
                  );

职位相关工作:

public $has_one = array(
    'request' => array(
        'class' => 'posts_m',
        'model_path' => 'application/modules/posts',
    )
);

By the way.

我设置instantiatefalse,转储数据减少到3.000行。

你没有做错任何事——事情就是这样。

试着理解PHP和CodeIgniter是如何工作的。

在PHP5中,所有对象都是通过引用赋值的。这意味着虽然您在访问Datamapper对象时看到它们,但它们是不复制,不占用内存

CodeIgniter的工作原理是将所有对象作为单例赋值给$thisvar_dump($this)将显示对象信息的页面和页面。访问CI的所有其他对象(通过自动机制)或者通过get_instance())使用引用。

显然你会在转储Datamapper对象时看到这些。因为Datamapper访问数据库、语言和表单验证库,这些库又链接到其他几个库。

http://ellislab.com/forums/viewthread/188420/# 890508


$instantiate -如果是TRUE,则实际对象被实例化并自动填充列。

http://datamapper.wanwizard.eu/pages/getadvanced.html

Instantiate TRUE意味着更多的数据。实例化FALSE意味着更少的数据