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

문제

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.

도움이 되었습니까?

해결책

  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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top