Fix SQL N+1 queries with RuboCop

SQL