Skip to content

Commit

Permalink
update active accounts to include new
Browse files Browse the repository at this point in the history
  • Loading branch information
ezekg committed Jul 26, 2024
1 parent 951f7c6 commit cf3857d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
33 changes: 18 additions & 15 deletions app/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,21 +123,24 @@ class Account < ApplicationRecord
end

scope :active, -> (with_activity_from: 90.days.ago) {
joins(:billing)
.where(billings: { state: %i[subscribed trialing pending] })
.where(<<~SQL.squish, with_activity_from)
EXISTS (
SELECT
1
FROM
"event_logs"
WHERE
"event_logs"."account_id" = "accounts"."id" AND
"event_logs"."created_at" > ?
LIMIT
1
)
SQL
base = joins(:billing).where(billings: { state: %i[subscribed trialing pending] })

new_accounts = base.where('accounts.created_at > ?', with_activity_from)
with_activity = base.where(<<~SQL.squish, with_activity_from)
EXISTS (
SELECT
1
FROM
"event_logs"
WHERE
"event_logs"."account_id" = "accounts"."id" AND
"event_logs"."created_at" > ?
LIMIT
1
)
SQL

new_accounts.or(with_activity)
}
scope :paid, -> { joins(:plan, :billing).where(plan: Plan.paid, billings: { state: 'subscribed' }) }
scope :free, -> { joins(:plan, :billing).where(plan: Plan.free, billings: { state: 'subscribed' }) }
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/keygen/stdout.rake
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace :keygen do
end

task eight: %i[environment] do
subscribers = User.stdout_subscribers
subscribers = User.stdout_subscribers(with_activity_from: 1.year.ago)
.where('stdout_last_sent_at IS NULL OR stdout_last_sent_at < ?', 7.days.ago)
.select(:id, :email, :first_name)
.reorder(:email, :created_at)
Expand Down

0 comments on commit cf3857d

Please sign in to comment.