sigmike/peer4commit — pull request #16 by mickzzz (2014-02-21 17:45:31+00:00)
Title: Optimize the 'update_cache' method for User class to remove extra queries

The current implementation of this method results in 2 queries per user for update along with 2 query per user to gather counts. Thats equal to 4 queries per 1 user.

The provided implementation eager-loads the 'tips' to avoid the 2*n queries for counts and also updates both the counts in a single update.

Hence, the number of queries run per user now is 1 with 1 additional query to eager_load all tips.
Thats around 300% reduced queries :smile: