speeding up pagination

I need help to optimize a query (sort of ...)

if params[:debit] == "on"   @schools = School.find(:all,     :conditions => ["name like ?", "%#{params[:search]}%"],             :order => 'name')          @schools.delete_if { |s| s.debit <= 0 }          @school_pages = Paginator.new self, @schools.length, 20

The problem here is that instance.debit is a virtual attribute ...

Any clue ?

   ngw

Hi, could you explain what issues you're seeing? Have you performed any timing tests with script/console?

-Conrad

Well, it's damn slow ... more than 1 minute to complete.

   ngw

Hey,

I need help to optimize a query (sort of ...)

if params[:debit] == "on"   @schools = School.find(:all,     :conditions => ["name like ?", "%#{params[:search]}%"],            :order => 'name')         @schools.delete_if { |s| s.debit <= 0 }         @school_pages = Paginator.new self, @schools.length, 20

The problem here is that instance.debit is a virtual attribute ...

If you're concluding that instance.debit is an attribute which cannot be calculated in an SQL query then you've got limited options.

Your first course of action would be to ensure there really isn't some way to have the 'debit' attribute calculated in SQL - find an expert with more knowledge/experience to help you.

After that, if it looks like SQL really isn't an option (or is so ugly and clunky that you lose sleep over it), look at caching the ruby-computed value of 'debit' in the schools table.

Regards, Trevor