Move calculation of giving and receiving to db.

In preparation to use trigger to cache the values for easy and fast
lookup. It will eventually allow us to remove the homepage updater
thread.