Minimizing calls to database in rails
Posted
by ming yeow
on Stack Overflow
See other posts from Stack Overflow
or by ming yeow
Published on 2010-05-22T17:04:07Z
Indexed on
2010/05/22
17:10 UTC
Read the original article
Hit count: 157
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
© Stack Overflow or respective owner