Rails action using an insane amount of MySQL/CPU


Try out the query analyzer plugin :

In no time you'll know if your are missing some obvious indexes, the
common cause for DB slowness.

.. and read this :
    Indexing for DB performance

Alain Ravet

I would also recommend using the paginator gem instead of the built-in
pagination of Rails. It is much more efficient. SInce I swapped them
out, I've had no problems.

gem install paginator

documentation: http://paginator.rubyforge.org/

that would work, just be sure to update the links for next/prev with
the new offset and limit

Also if you have all your images in the database, this could be the
main cause for the slowness, send back so much data can take a while,
even if the actual query is quick. I don't know it would be possible,
but consider maybe using Amzon S3 service if your number of image will
increase and the number of requests increase. Then just keep a
reference of the names in database, this should inprove the
effecientcy more.