Hi there, I am working on an events site where there are a bunch of
different calendars (for different groups of people) that display
submitted events that belong to that calendar, the dates for the events
are kept as Occurrence objects.
This code works fine, it just takes really long to load a page if I use
it, it pulls events for a particular calendar from the database and
displays the event info on the page. Any suggestions on how to speed it
up? I'm pretty sure it takes a long time because it's pulling all the
occurrences (theres a lot of them) of all events from the database and
then going through all of those and rejecting all but the few events
that belong the necessary calendar.
@calendar = params[:cal]; # calendar for the events to belong to
@length = params[:length];
@limit = params[:limit]; # tells how many events are being called for
if @limit == nil
@limit = '-1';
if @length == 'all'
@occurrences = @calendar.all_events()
def all_events() #the part that I think takes forever to load
o = Occurrence.find_all_events()
o.reject do |c|
c.event.nil? || !c.event.calendars.include?(self)
Thanks for any help!