I’m working on a legacy CakePHP app built on the 1.3.x branch, which makes heavy use of the Containable behavior and specifically deep nested contains.
It has become apparent that this is a massive performance issue due to the way CakePHP framework handles the queries underneath deep contains. In one request we have over 10K queries followed by Cake merging the data together into an array.
Can anyone confirm if these issues are fixed in the Cake 2.x branch and by upgrading the framework we could make headway on performance issues.
Due to time constraints, we can currently either upgrade or tackle re-writing parts of the system to not use Containable, but not both.
I would prefer to upgrade as there are other benefits to be had, but I need to be sure that our performance issues will be tackled.
Example of deep nested contain
$this->Event->find('all', array(
'conditions' => $conditions,
'contain' => array(
'SessionDay' => array(
'Activity' => array(
'TimeSlot' => array(
'TimeSlotBooking',
'order' => array('slot_time' => 'asc')
)
)
),
'Activity' => array(
'TimeSlot' => array(
'TimeSlotBooking',
'order' => array('slot_time' => 'asc')
)
),
'Interview' => array(
'InterviewBooking',
'order' => array('interview_time' => 'asc')
),
'EventCode'
)
)
);
I have been using very deep nested containable queries on a project with Cake 2.x and they work well.
It still produces multiple queries and in some cases instead of doing
it will do:
So you can end up with a lot of queries. At the end of the day it’s going to depend on how many rows you actually need to retrieve from all your tables.
I’d suggest installing another Cake 2 project along side using the same database. Just quickly copy over your models and run your biggest query, then look at the difference in the query debug output for any differences.