Minimizing calls to database in rails
- by ming yeow
Hi guys, i am familiar with memcached and eager loading, but neither seems to solve the problem i am facing. 
My main performance lag comes from hundreds of data retrieval calls from the database. The tricky thing is that I do not know which set of users i need to retrieve until i have several steps of computation. 
I can refactor my code, but i was wondering how you experts handle this situation? I think it should be a fairly common situation
def newsfeed
  - find out which users i need
  - retrieve those users via DB
  - find out which events happened for these users
  - for each of those events
        - retrieve new set of users
  - find out which groups are relevant
  - for each of those groups
        - retrieve new set of users 
  - etc, etc 
end