Retrieve tomatoes counters from user's scores
Right now GET / and GET /api/user return three counters that include:
- current user's number of tomatoes completed today
- current user's number of tomatoes completed this week
- current user's number of tomatoes completed this month
These numbers are computed dynamically running a count query on a subset of tomatoes. The method to count current user's tomatoes completed within a period of time is defined as:
def tomatoes_counter(time_period)
tomatoes.after(Time.zone.now.send("beginning_of_#{time_period}")).count
end
where time_period is included in [:day, :week, :month].
Alternatively we could just rely on score collections to retrieve cached counters. This method would run a query against one of the collections, for instance DailyScore, to find the user's score. The number of queries would be the same, but queries against *Scorecollections would be slightly faster and would alleviate load on the tomatoes collection.
This proposal is blocked by https://github.com/tomatoes-app/tomatoes/issues/258.