How you will handle complicated web page where you must display one User account with a lot of relations (15+)
The translation data is kept on separate tables (globalize2/3) so the queries rised to 30+.
Putting the ACL and some logging and you will got 45+ queries sometimes 65+
I don't want to split the page on multiple screens all data is required on one screen.
Cu开发者_如何学JAVArrently I have pre-loaded all the relational tables for the User in a global variable in the Rails and it works fine except it is complicated to maintain the cache with all the sync and translation data.
I have tried memcached but it was slow because each object has to be serialized/de-serialized on every request.
What is the best way to handle such page(s)?
If you have a single model with a bunch of relationships, eager loading with "include" should help you significantly. In Rails 2.3 It works something like:
User.find(1, :include => [:relationship1, :relationship2, :relationship2])
Agreed, the "include" option for ActiveRecord should help a lot. However don't forget you can also nest associations. For instance say you have the following setup.
User
- Blog
- Posts
- Comments
- Images
- Comments
- Videos
- EncodedVideos
The can be setup in ActiveRecord as:
User.find(:all, :include => {:user => [{:blog => {:posts => :comments}}, {:images => :comments}, {:videos => :encoded_videos}]})
Hope this helps.
Another way might be to store the collections under the client browser
http://www.gudasoft.com/english/development/rails-development/10/28/1342/store-data-in-the-browser-with-rails-and-jquery/2010
精彩评论