Speed up recursive loop or get rid of it?

so..

I'm making a scheduler.. i have a table of scheduled and scheduleable
hours for multiple users which needs to be turned into a view (with
schedule type as there are 4 different types) of 7 days of those
scheduled and scheduleable hours for multiple users..

right now i've a loop which iterates over every hour and tests it
against all the returned scheduleable and scheduled hours for those 7
days...

it's really slow.. the loop that figures out the schedule type runs like
1000 times and just obliterates my processor locally while it's running.

anyone have any suggestion of how to speed things up? i've been
thinking about it but can't seem to come to a speedier conclusion.

Morgan -

My suggestion is to drive things from the view requirements. What does your view actually need to output? From there, work backwards to the code required.

If you give us morecontect, we can help further.

Blog: http://random8.zenunit.com/
Twitter: http://twitter.com/random8r
Learn: http://sensei.zenunit.com/
New video up now at http://sensei.zenunit.com/ real fastcgi rails deploy process! Check it out now!

Jodi, thanks for posting the above two links and I’m sure that others will

find them helpful as well.

-Conrad

So you have a model hour, and it belongs to a model hour type and also belongs to a user?

Then your controller loads users, :include => hours and hour type

Then, your view loops the users one row per user, loops one cell per hour, and prints the type.

Simple?!

Blog: http://random8.zenunit.com/
Twitter: http://twitter.com/random8r
Learn: http://sensei.zenunit.com/
New video up now at http://sensei.zenunit.com/ real fastcgi rails deploy process! Check it out now!

Morgan Morgan wrote:
[...]

hrmm. i guess it would make more sense to do a bunch of db querys and
parse small amounts of data instead of doing one big db call and parsing
large amounts of data..

No. Ask for all the records you need in as few queries as possible
(remember that AR will take arrays of IDs, as well as all manner of
other conditions). Many little queries is generally a sign that
something is wrong.

Best,