How to speed up a page with 45+ requests

How will you handle a complex web page where you have to display one user account with a lot of relationships (15+)

Translation data is stored in separate tables (globalize2 / 3), so requests are increased to 30+.

Put the ACL and some entries and you will get 45+ requests sometimes 65+

I do not want to split the page on multiple screens, all data is required on one screen.

Currently, I have preloaded all the relational tables for the user in a global variable in Rails, and it works fine, except that it is difficult to maintain a cache with all synchronization and translation data.

I tried memcached, but it was slow because every object needs to be serialized / de-serialized for every request.

What is the best way to handle such pages?

+3
source share
3 answers

If you have one model with many relationships, then intensive loading with include should help you a lot. In Rails 2.3, it works something like this:

User.find(1, :include => [:relationship1, :relationship2, :relationship2])
+3
source

I agree, the "enable" option for ActiveRecord should help a lot. However, do not forget that you can also establish associations. For example, let's say you have the following setting.

User
 - Blog
   - Posts
     - Comments
 - Images
   - Comments
 - Videos
   - EncodedVideos

In ActiveRecord, you can configure it as:


User.find(:all, :include => {:user => [{:blog => {:posts => :comments}}, {:images => :comments}, {:videos => :encoded_videos}]})

Hope this helps.

0
source

Source: https://habr.com/ru/post/1765711/


All Articles