Wednesday, September 5, 2012

SLOW: Controller function with many unrelated Models

Hello,

I'm wondering about the best way to speed up my page load.
I have a View that displays a table with data from around 15 different Models.
Many of them are unrelated.  A few are in different databases.

The MySQL query is around 2 seconds (I can see from an sql_dump),
but the page can take over 30+ seconds to load.

It is obviously from the the loading of so many models in my controller for
that view. 

My controller functions in question (take index for example) are simply
calls to Model methods like thus:

function index ($siteOID) {
        $this->Site->recursive = -1;
       
        $listSites = $this->Site->listAllSites($siteOID);
        $this->set('listSites', $listSites);
   
        $activeAdvertisers = $this->Site->Flight->countActiveAdvertisers();
        $this->set('activeAdvertisers', $activeAdvertisers);
       
        etc...


Originally the models were all in var $uses, and so I'm searching for another option,
but since I need them all for this particular page view, I don't see how loadmodel()
would make any difference since I would have to load each model anyhow.

I tried using this style of calling the methods: $this->model->model->model->method()
inside the controller function, for the ones that had associations (and thus taking them out of the $uses),
but this doesn't seem to change the page load.

What other ways can I save this page from being so SLOWWWW.
Or is this just the price for trying to stick so many columns of unrelated tables
on a single page...?

Thanks!
alexander

--
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
 
 

No comments: