BushyMark wrote: > > I was wondering what others did when faced with this? My thought has > been to initialize a bunch of "virtual attributes" when instantiating > the DaySchedule object back in the model. (going from > DaySchedule.employee.full_name to a DaySchedule.full_name method that > I set up with initialize so it is in memory). Does this sound like the > right thing to do? What are best practices when an object has a large > amount of associations with other models and the view needs access to > those related objects?
Cache baby, cache... if your initial page views show information that changes infrequently, or groups of information that change infrequently, caching the fragments that make up those views can save you lots of time. Another option is to create a view that marshall's the data in the format you want it and let the database do all the hard work. Caching stuff: In my apps 'show' for any given model, the right side context navigation shows a list of all the related models and provides a hyperlink to each of them. This right side div is composed of a hierarchy of cached fragments (some models have as many as 9 related types of models (call this n), each type with m related model instances). The top level cache is the full context menu, and there are n sub-fragments that make up the top level one. Add/Edit/Delete a related entity, and that sub fragment is invalidated, and the top level fragment also. The next show reads records only to refresh that sub-fragment and then reconstructs the top level fragment from the other fragments. Comparing load times from a cold cache (after a rake tmp:cache:clear), versus a simple redisplay or adding/dropping 1 related model instance yields an order of magnitude difference or more, depending on how many related models there are, and this is all still file-based caching. -- Posted via http://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 [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

