slow index action / search via ransack

95 views
Skip to first unread message

www.ezh...@gmail.com

unread,
Jul 18, 2017, 10:08:55 AM7/18/17
to Ruby on Rails: Talk
hi,

when i run my index action it takes forever to load up (www.ezhubb.com/search). how
can i speed up the mysql / rails process? 

i do try to limit the results, but this code is not working:
@q = MyModel.order("RAND()").limit(100).ransack(:some_field => Date.today )
@q.result(distinct: true).includes(:user).paginate(page: params[:page], per_page: 30) #.order("RAND()")

any ideas how to speed this up? ho wmany record should i pull when no search criterias are given? everything is still on default settings (mysql, nginx etc..) thx

Mugurel Chirica

unread,
Jul 19, 2017, 5:09:21 AM7/19/17
to rubyonra...@googlegroups.com
This gem could help you rack-mini-profiler.

Cheers

www.ezh...@gmail.com

unread,
Jul 19, 2017, 9:22:41 AM7/19/17
to Ruby on Rails: Talk
looks promising - will try
thx

Colin Law

unread,
Jul 19, 2017, 10:14:07 AM7/19/17
to Ruby on Rails: Talk
On 18 July 2017 at 14:53, <www.ezh...@gmail.com> wrote:
> hi,
>
> when i run my index action it takes forever to load up
> (www.ezhubb.com/search). how
> can i speed up the mysql / rails process?
>
> i do try to limit the results, but this code is not working:
> @q = MyModel.order("RAND()").limit(100).ransack(:some_field => Date.today )
> @q.result(distinct: true).includes(:user).paginate(page: params[:page],
> per_page: 30) #.order("RAND()")

I am not an expert on this but I suspect that MyModel.order("RAND()")
may be horrendously slow on a table with a large number of rows. You
could see if this is the issue by removing the order clause to see if
it makes a big difference.

Colin

>
>
> any ideas how to speed this up? ho wmany record should i pull when no search
> criterias
> are given? everything is still on default settings (mysql, nginx etc..)
>
> thx
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rubyonrails-talk/dc4958a3-838f-40ef-8708-2d59cf26a120%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages