Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing MySQL views in a Ruby on Rails app to improve performance
    primarykey
    data
    text
    <p>I'm having some performance issues in a rails project (running on rails 2.0.5), for example in my user administration pages.</p> <p>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.</p> <p>I used to develop on Java &amp; 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...</p> <p>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 ?</p> <p>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 ):</p> <pre><code>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 ; </code></pre> <p>Then a model:</p> <pre><code>class UsersV &lt; ActiveRecord::Base end </code></pre> <p>Tried a few things in my console:</p> <pre><code>u=UsersV.find(:first) # ok ! u=UsersV.find_by_last_name('smith') #=&gt; ok ! us=UsersV.find_all_by_last_name('smith') #=&gt; ok too ! </code></pre> <p>looking at the log, simple queries are just handled the same way as any table queries</p> <p>Of course, those fake models would just be used to read datas.</p> <p>I'm wondering:</p> <ul> <li><p>if someone already tried that ?</p></li> <li><p>if it's a good idea ?</p></li> <li><p>if I should look into something like memcached instead...</p></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload