From 14e700fa504ff304544d4f51f684ccad0615051b Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Sat, 28 Apr 2018 00:35:24 +0200 Subject: [PATCH] Adds query for daily engaged users --- app/models/user_action.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/models/user_action.rb b/app/models/user_action.rb index 073e2ec08ae..f20cc8c6376 100644 --- a/app/models/user_action.rb +++ b/app/models/user_action.rb @@ -1,4 +1,6 @@ class UserAction < ActiveRecord::Base + include DateGroupable + belongs_to :user belongs_to :target_post, class_name: "Post" belongs_to :target_topic, class_name: "Topic" @@ -119,6 +121,13 @@ SQL end + def self.count_daily_engaged_users(start_date, end_date) + select(:user_id).distinct + .where(action_type: [LIKE, NEW_TOPIC, REPLY, NEW_PRIVATE_MESSAGE]) + .smart_group_by_date(:created_at, start_date, end_date) + .count + end + def self.stream_item(action_id, guardian) stream(action_id: action_id, guardian: guardian).first end