> You can make that a tad more efficient by doing > > def add_rolling_event(id, title, calendar_date) > (@events[calendar_date.to_date] ||= []) << > RollingEvent.new(id, title, calendar_date) > end > Gotcha :-) > > What do you mean by "indexed array"? I am not sure what your #to_date > returns so you might be using a Hash or an Array. Ultimately when it > comes to "faster" you need to implement different variants and benchmark > them. Fortunately this is pretty easily done in Ruby. Sorry, my terminology needs work - #to_date returns a date value so I'm using a Hash. I'll certainly benchmark the variants. > Well, it seems you have to access paths to an event: lookup by date and > lookup by event id. I do not know whether there are other access paths > (e.g. search for event name or such) but assuming for the moment that > there are just the two a solution with two Hashes seems most appropriate > That's correct! And by highlighting the access paths you've helped me narrow it down to one of the challenges I've come across. I have the event id which I could use to delete an event from the array indexed by event hash - but this doesn't delete the event indexed by id hash (or does it? I'll give it a go). > There are a lot other factors that you need to consider when thinking > about the database. 3600 events is certainly a small number, even when > read from a flat file. You rather want a DB if your application needs > to run on multiple machines concurrently and you want to have a single > repository etc. As long as you can foresee that there will not be > millions of entries I would probably not complicate the application by > adding another component. That's good advice. Thanks Robert! -- Posted via http://www.ruby-forum.com/.