Ruby on Rails Sunday, January 30, 2011

>
> Hi Fred,
>
> Mainly speed/performance but these 'events' are looped through all over
> the show.  I think it'd be impractical to write a method for each unique
> set of criteria:
>
>   er = get_eventroster
>   the_date = "2010-12-31".to_date
>
>   er.allevents.select{|e| e.calendar_id == 20135 && e.amount >= 500.0 &&
> e.calendar_date == the_date}.each{|e| balance += e.amount}
>
> is far more flexible than, say:
>
>   er.get_events_by_calendar_id_and_amount_greater_than_and_date(20135,
> 500.0, the_date).each{|e| balance += e.amount}
>
> I have already tried something like:
>
> er.allevents.select{|e| e.calendar_id == 20135 && e.amount >= 500.0 &&
> e.occurs_on(the_date)}.each{|e| balance += e.amount}
>
> but these events are being looped through in many places throughout my
> application and this slowed the creation of a 1-year forecast calendar
> from 0.5 seconds (where there was an individual event for every
> instance) to 5.5 seconds (where each event held an array of dates
> representing its instances) and 50-60 seconds (where the event held a
> single date and occurrences where calculated on the fly based on repeat
> information)
>
> Using functions to calculate the number of occurrences between two dates
> (etc) slows it down but lightens the amount of data stored in session.
> The purpose of this challenge was to satisfy both--keep it fast but
> don't repeat all the data that each event contains.
>
> Does anybody know how I could loop through every instance of an event
> and call it's parent events methods?
>

Why do event occurrences not store their parent event rather than the
object_id? Whatever you do ObjectSpace is really best avoided. I'm
still not sure why this is better/more expressive than calculating
them on the fly - you're clearly able to calculate the occurrences
pragmatically, so I don't see why calculating them ahead of time would
be less flexible/slower than calculating them on demand (provided you
cache things so that you don't calculate things repeatedly)

Fred

Fred
> --
> Posted viahttp://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment