Commit f17f6040 authored by Sean McGivern's avatar Sean McGivern Committed by Rémy Coutable

Use last_activity_on in cohorts

parent a67b6b38
...@@ -68,24 +68,24 @@ class CohortsService ...@@ -68,24 +68,24 @@ class CohortsService
# Get a hash that looks like: # Get a hash that looks like:
# #
# { # {
# [created_at_month, current_sign_in_at_month] => count, # [created_at_month, last_activity_on_month] => count,
# [created_at_month, current_sign_in_at_month_2] => count_2, # [created_at_month, last_activity_on_month_2] => count_2,
# # etc. # # etc.
# } # }
# #
# created_at_month can never be nil, but current_sign_in_at_month can (when a # created_at_month can never be nil, but last_activity_on_month can (when a
# user has never logged in, just been created). This covers the last # user has never logged in, just been created). This covers the last
# MONTHS_INCLUDED months. # MONTHS_INCLUDED months.
def counts_by_month def counts_by_month
@counts_by_month ||= @counts_by_month ||=
begin begin
created_at_month = column_to_date('created_at') created_at_month = column_to_date('created_at')
current_sign_in_at_month = column_to_date('current_sign_in_at') last_activity_on_month = column_to_date('last_activity_on')
User User
.where('created_at > ?', MONTHS_INCLUDED.months.ago.end_of_month) .where('created_at > ?', MONTHS_INCLUDED.months.ago.end_of_month)
.group(created_at_month, current_sign_in_at_month) .group(created_at_month, last_activity_on_month)
.reorder("#{created_at_month} ASC", "#{current_sign_in_at_month} ASC") .reorder("#{created_at_month} ASC", "#{last_activity_on_month} ASC")
.count .count
end end
end end
......
...@@ -11,8 +11,8 @@ describe CohortsService do ...@@ -11,8 +11,8 @@ describe CohortsService do
6.times do |months_ago| 6.times do |months_ago|
months_ago_time = (months_ago * 2).months.ago months_ago_time = (months_ago * 2).months.ago
create(:user, created_at: months_ago_time, current_sign_in_at: Time.now) create(:user, created_at: months_ago_time, last_activity_on: Time.now)
create(:user, created_at: months_ago_time, current_sign_in_at: months_ago_time) create(:user, created_at: months_ago_time, last_activity_on: months_ago_time)
end end
create(:user) # this user is inactive and belongs to the current month create(:user) # this user is inactive and belongs to the current month
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment