1
votes

i am developing with cakephp (2.4.7) and i am using the containable option.

I have a few find statements with about 15 Tables/Models inside the containable array and my query log shows about 60-100 queries.

Should i use joins instead of containable due to better performance?

My site requires high performance standard.

And is it possible to join automatically based on the linking models like containable, or do i have to set up the joins manually like:

Example:

 $this->Message->find('all', array(
    'joins' => array(
        array(
            'table' => 'users',
            'alias' => 'UserJoin',
            'type' => 'INNER',
            'conditions' => array(
                'UserJoin.id = Message.from'
            )
        )
    ),
    'conditions' => array(
        'Message.to' => 4
    ),
    'fields' => array('UserJoin.*', 'Message.*'),
    'order' => 'Message.datetime DESC'
));

Guide me the correct way to achieve my objective.

1

1 Answers

0
votes

Contain takes a lot of system resourses to product a data from tables since it is make a lot of queries and apply Hash::nest() function to each of them.

But with joins you will get a lot of dublicated data, and you will need to extract data from it by yourself. Not the best solution, huh.

I don't know which one will be better for you, but the best way to get most performance results is to get use index in your tables and cache.