-
Notifications
You must be signed in to change notification settings - Fork 91
Open
Description
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 *Score
collections would be slightly faster and would alleviate load on the tomatoes
collection.