Topic: Activerecord vs Ruby searches
I'm writing an application where the central feature is a calendar. The calendar is essentially just a table (to make it look as similar as possible to the paper original currently being used), rendering a complete month, with a header and a cell for each day in the month. For each day, the shifts for every person have to be displayed and a couple of checks (for gaps in coverage) have to be made. The result is unfortunately slower than I would like (3-6 seconds in development).
I was originally accessing the database each day to find and pull out the shifts for that day. I thought one major source of inefficiency would be performing all those fetches from the database. However I didn't really notice any difference in render time for the page when I started fetching all the shifts for the month at once and then using ruby to select the right ones for each day. The ActiveRecord time decreases, but the overall view time doesn't change much.
So my question is:
Is it really more efficient to collect all the shifts for the month one time using model.where, and then sort through them each day using ruby's array.select? Or is there something I'm missing that might be able to help speed up the process?
On a related note, is it typical for render times to vary hugely in development mode? It seems odd that the time to render the same month is randomly different by as many as 3 seconds.