I am using Ruby on Rails 3.1.10 in developing a web application.
Objective is to find all users that a user is following.
Let there be two models User
and Following
In User
model:
has_many :following_users, :through => :followings
When calling user.following_users
, rails help generates a query that INNER JOIN between users
and followings
table by its magical default.
When users
table has over 50,000 records while followings
table has over 10,000,000 records, the inner join generated is resource demanding.
Any thoughts on how to optimize the performance by avoiding inner joining two big tables?