Hi,
I currently have a large array of model objects (around 5000 this
could grow to be in the 100k range) which have a date attribute. I
want to filter this objects if one of their date attribute falls into
an array of years selected by the user. I wrote the code to do this
in ruby land:
def FilterUtils.apply_year_filter readings, years
readings.each {|reading|
if( reading.timestamp != nil && years != nil &&
years.index(reading.timestamp.year) == nil )
readings.delete(reading)
end
}
readings
end
but its too slow so I’m going to do it through a :conditions query on
the .find(:all) call rather than fetching them all back and filtering
through them afterwards.
As far as I can tell there’s no built in date queries in the active
record interface. I’ve done about an hour of searching and no dice.
I’m currently writing the custom sql to do this in our postgres db but
was just curious if there was an efficient way to do this without
tying the project to postgres.
Thanks
Barry
