Cake PHP: Containable Behavior or Model Unbind - which is good for Optimizing Query in Cake PHP

StackOverflow https://stackoverflow.com/questions/22758729

  •  24-06-2023
  •  | 
  •  

Question

I'm working on a project based on Cake PHP.On that project recursive = 2 is used and that makes the application slow. Now I need To Optimize Some Query for slow response. For optimizing Query I can Follow two steps:

1. UnbindModel

2. Containable Behavior

My Question is When I Should use Containable Behavior and when unbinding Models.I Think I need Some Clear Explanation From Cake PHP Expert.

Was it helpful?

Solution

  1. You should always be using either Containable or recursive=>'-1'
  2. Cache your queries when it's possible (when you're requesting the same data multiple times)
  3. Only ask for what you need using the fields parameter
  4. Add appropriate indexes to your MySQL database tables

Those are just some of the quickest ways to optimizes your queries. There are also ways to optimize queries using bindModel for certain requests, or restructuring your tables in certain ways, but those are very situation-specific.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top