Announcement (2017-05-07): www.ruby-forum.com is now read-only since I
unfortunately do not have the time to support and maintain the forum any
more. Please see rubyonrails.org/community and ruby-lang.org/en/community
for other Rails- und Ruby-related community platforms.

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.

On 20/05/2009, at 12:57 AM, Morgan Morgan
<rails-mailing-list@andreas-s.net
> wrote:
> against all the returned scheduleable and scheduled hours for those 7>
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!

Morgan Morgan wrote:
> it's basically just a calendar view from 8am to 12pm with colours for> each of the schedule types returned>> so it's a grid
Can you change the model then? It sounds like something easier done the
other way around, ie, you iterate through the things that are scheduled
for when they are scheduled, and get rid of the calendar in the model --
just implement it in the view based on the database of things scheduled.

On 20/05/2009, at 3:21 AM, Morgan Morgan
<rails-mailing-list@andreas-s.net
> wrote:
>> r> r b>
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!

Julian Leviston wrote:
> On 20/05/2009, at 3:21 AM, Morgan Morgan> <rails-mailing-list@andreas-s.net> > wrote:>>>>> r>> r b>>> 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!
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.. i'll see if calms it down when it's more
balanced.
thank you.

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,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org

Marnen Laibow-Koser wrote:
> 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,> --> Marnen Laibow-Koser> http://www.marnen.org> marnen@marnen.org
well say i had 25 users, i'd be doing 25 querys right. one for each
user then looping through the results in basically the same way i was
doing it before?

Morgan Morgan wrote:
[...]
> well say i had 25 users, i'd be doing 25 querys right. one for each> user then looping through the results in basically the same way i was> doing it before?
Gosh, I hope not. :) Fetch it all in one query with lots of joins, then
loop through the recordset in memory.
In general, DB queries don't belong inside loops. Use the power of the
database instead!
Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org