📜 ⬆️ ⬇️

3 simple tips that will make your Rails application faster, part # 2

We continue to optimize our applications written in Ruby on Rails. The first part of the article is here.
Tip # 1: Clean up your static content.
Tip # 2: Remove all unnecessary
Tip # 3: Cache the whole page

Tip # 2: Remove all unnecessary

Authentication, access to sessions, verification of user rights and unnecessary requests to the database. Do you really need to do all this with every request to the server?

You can disable sessions for specific Actions simply by specifying:
session :off, :only => :index

This significantly improves performance and is an excellent alternative for caching, if you need to access the database but there is no need to check user rights.
')
If you are using RestfulAuthentication or ActsAsAuthenticated plugins, you can disable user rights checking for some Actions, which will save a single query to the database for you.
skip_filter :login_from_cookie
or
skip_filter :login_required
well, or what else have you got there ...

Using fragment caching for your Partials skip requests to the database in your controller via read_fragment
@users = User.find('all) unless read_fragment('unique_cache_key')

Also, do not forget to correctly use the: include option in your queries to load associations.
Post.find(:all, :include => :user)

This will reduce the number of requests by 2 times.

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


All Articles