I am realizing my first application in Rails (with tutorials), I
implement a pagination solution with will_paginate gem, it works well
but the problem is: changing pages is very slow and I think the query is
executed every time the page is changing
Is there a solution to get faster pagination
I am thinking about redis, is there a way to use it with will_paginate
the query : User.find(:all,:order => "name")
When using paginate you should not be finding all records, only the
ones you need for the page. Does your tutorial cover this? I would
have expected it to be something like
@users = User.paginate :page => params[:page], :per_page => 10, :order => 'name'
However unless you have thousands of users I would not have expected
this to be an issue. If you are running in development mode you can
look in development.log to see how long the queries take.
If you are sorting on name you should probably have a database index
on that field, but again unless you have many users I would not have
expected to see a problem.
If you are running in development mode then you can expect it to be
slower than in production because it will load all the files at each
request, in production they are cached. The reason for this is so
that in development mode you do not need to restart the server if you
change a file.