tomatoes icon indicating copy to clipboard operation
tomatoes copied to clipboard

Retrieve tomatoes counters from user's scores

Open potomak opened this issue 8 years ago • 1 comments

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.

potomak avatar Jan 28 '17 23:01 potomak

This proposal is blocked by https://github.com/tomatoes-app/tomatoes/issues/258.

potomak avatar Feb 12 '17 22:02 potomak