Question

I'm using codeIgniter 2.1.4 with Datamapper and i worry about Datamapper performance.

My results are only 2 rows and return successfully!

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..

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',
    )
);

By the way..

I set instantiate as false and dumped data decreased to 3.000 lines.. I really didnt understand..

Était-ce utile?

La solution

You aren't doing anything wrong -- this is just the way it is.

Try to understand how PHP, and CodeIgniter work.

In PHP5, all objects are assigned by reference. This means that although you see them when you access a Datamapper object, they are not copies, and don’t take up memory.

CodeIgniter works by assigning all objects as singletons to $this, so a var_dump($this) will show you pages and pages of object information. All other objects that access CI ( either via an automatic mechanism or through get_instance() ) use references.

So obviously you’ll see all this when you dump a Datamapper object. Because Datamapper accesses the database, language, and form validation libraries, which in turn have links to several other libraries.

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


$instantiate - If TRUE, then actual objects are instantiated and populated with the columns automatically.

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

Instantiate TRUE means more data. Intantiate FALSE means less data.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top