ab5283441d
* Add saas:usage_report rake task and extract Subscription.paid scope Add a rake task to generate a CSV usage report with per-account data: Queenbee ID, sign up date, paid date, card count, storage used, and last active date. Extract the paid subscriptions query from Admin::StatsController into an Account::Subscription.paid scope so both the controller and the new rake task can share it. * Add comped and account name columns to usage report * Update saas/lib/tasks/fizzy/usage_report.rake Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Preload storage_total to avoid N+1 in usage report * Batch last_active_at queries to avoid per-account aggregates * Add tests for Account::Subscription.paid scope * Update saas/app/models/account/subscription.rb Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Aggregate paid dates in SQL instead of loading all subscriptions * Fix paid scope to derive plan keys from Plan.all instead of PLANS hash * Move paid dates and comped lookups into per-batch queries * Materialize batch IDs to avoid cross-database subquery SaasRecord models live on a separate database (fizzy_saas) that doesn't have the accounts table. Using batch.select(:id) generated a subquery that ran on the saas database, causing a table-not-found error. Using pluck(:id) materializes the IDs into an array instead. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
25 lines
978 B
Ruby
25 lines
978 B
Ruby
class Admin::StatsController < AdminController
|
|
layout "public"
|
|
|
|
def show
|
|
@accounts_total = Account.count
|
|
@accounts_last_7_days = Account.where(created_at: 7.days.ago..).count
|
|
@accounts_last_24_hours = Account.where(created_at: 24.hours.ago..).count
|
|
|
|
@paid_accounts_total = Account::Subscription.paid.distinct.count(:account_id)
|
|
@paid_accounts_last_7_days = Account::Subscription.paid.where(created_at: 7.days.ago..).distinct.count(:account_id)
|
|
@paid_accounts_last_24_hours = Account::Subscription.paid.where(created_at: 24.hours.ago..).distinct.count(:account_id)
|
|
|
|
@identities_total = Identity.count
|
|
@identities_last_7_days = Identity.where(created_at: 7.days.ago..).count
|
|
@identities_last_24_hours = Identity.where(created_at: 24.hours.ago..).count
|
|
|
|
@top_accounts = Account
|
|
.where("cards_count > 0")
|
|
.order(cards_count: :desc)
|
|
.limit(20)
|
|
|
|
@recent_accounts = Account.order(created_at: :desc).limit(10)
|
|
end
|
|
end
|