views:

23

answers:

2

Hi there,

I am scratching my head over for this issue for last few weeks.

My local rails dev environment has been so slow for some reasons. I have production environment working as quick as a bullet on the servers. But with the same code, my dev environment is taking so slow and I have decided to dig into that further.

I have found that the problem exists with two of my main models. I could identify it with Console in the terminal.

Admin.last 
#(super quick, no records there)
Club.last 
#(super quick, about 1400 records there)

User.last 
#(super slow, about 3 seconds. but no records in there yet!!!!)
Site.last 
#(super slow,about 3 seconds, too.. but this one has about 4000 records)

Admin and User has almost the same number and type of fields except User has a photo (using Paperclip). But paperclip is working fine with Club anyway.

Any help will be appreciated.

Thanks.

EDIT: I have found more precise issue there. In both User and Site models, I have this reference which is slowing things down on my dev env.

include ActionController::UrlWriter

I know we should not use URL in the model level. But I have to use it. The question now is why the heck it's slow to use it only on Dev env, not on production? Thanks.

+1  A: 

it's because your URL are reload in each time. So take some times. In production there are no reload of your route.

shingara
+2  A: 

In the development environment code is reloaded after each request and not cached. This means you can make changes to the code and just refresh the page and not have to refresh the server.

In production mode routes/models are cached as these are less likely to be edited between requests without a server restart.

David Lyod
Thanks. It makes sense. I have just removed the code to stay outside (application controller) of the model and avoid using the reference in the models. And it works great now.
Phyo Wai Win