I'm having some performances issues in a rails project (running on rails 2.0.5), for example in my user administration pages.
my user model has many relations (details, addresses, roles...) who get loaded with eager loading. That creates really huge SQL queries, for some cases, it takes almost a minute to load 30 users. On the other hand removing the eager loading generates hundreds of queries, in the end I have the same problem: loading the page is slow.
I used to develop on Java & Oracle, for this kind of big queries I used to create views, those views were then cached for a faster rendering. It was extremely boring to maintain, as I had to update the database fields manually in the views scripts etc...
BUT it really had fantastic performances.... so I was wondering if anyone ever tried to implement something to take benefits of Mysql views in active record ?
I just did some basic tests, here's my view (just a few fields for the example, I have a standard Restful Authentication user table, and a big table "details" for the personal datas ):
CREATE VIEW users_vs AS SELECT
users.id ,
users.login ,
users.email ,
details.last_name ,
details.first_name ,
details.phone ,
details.fax ,
FROM `users` LEFT OUTER JOIN `details` ON details.user_id = users.id ;
Then a model:
class UsersV < ActiveRecord::Base
end
Tried a few things in my console:
u=UsersV.find(:first) # ok !
u=UsersV.find_by_last_name('smith') #=> ok !
us=UsersV.find_all_by_last_name('smith') #=> ok too !
looking at the log, simple queries are just handled the same way as any table queries
Of course, those fake models would just be used to read datas.
I'm wondering:
if someone already tried that ?
if it's a good idea ?
if I should look into something like memcached instead...