Skip to content

Commit

Permalink
Performance on stats page
Browse files Browse the repository at this point in the history
  • Loading branch information
parterburn committed Sep 4, 2024
1 parent cb630be commit 453d6f9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 44 deletions.
17 changes: 7 additions & 10 deletions app/controllers/admin/stats_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ class Admin::StatsController < ApplicationController
def index
@dashboard = AdminStats.new
@users = User.all
@entries = Entry.all

# Preload data for charts
@users_by_week = @dashboard.users_by_week_since(90.days.ago)
Expand All @@ -18,14 +17,13 @@ def index

# User statistics
@total_users = @users.count
@pro_users = @users.pro_only
@free_users = @users.free_only
@monthly_users = @users.monthly
@yearly_users = @users.yearly
@forever_users = @users.forever
@payhere_users = @users.payhere_only
@gumroad_users = @users.gumroad_only
@paypal_users = @users.paypal_only
@pro_users = @users.pro_only.count
@monthly_users = @users.monthly.count
@yearly_users = @users.yearly.count
@forever_users = @users.forever.count
@payhere_users = @users.payhere_only.count
@gumroad_users = @users.gumroad_only.count
@paypal_users = @users.paypal_only.count
@referral_users = @users.referrals

# Email statistics
Expand All @@ -35,6 +33,5 @@ def index
# Paginate large datasets
@upgrades = @dashboard.upgraded_users_since(90.days.ago).page(params[:upgrades_page]).per(20)
@bounces = @dashboard.bounced_users_since(90.days.ago).page(params[:bounces_page]).per(20)
@free_users_recent = @dashboard.free_users_created_since(90.days.ago).order(:created_at).page(params[:free_users_page]).per(20)
end
end
8 changes: 0 additions & 8 deletions app/views/admin/stats.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,3 @@
%h3 #{pluralize(format_number(@bounces.total_count), "user")} from the last 90 days has had emails bouncing
= render partial: 'bounces_table', locals: { bounces: @bounces, dashboard: @dashboard }
= paginate @bounces, param_name: 'bounces_page'

.col-md-12
%hr

.col-md-12
%h3 #{pluralize(format_number(@free_users_recent.total_count), "Free User")} from the last 90 days
= render partial: 'free_users_table', locals: { free_users: @free_users_recent, dashboard: @dashboard }
= paginate @free_users_recent, param_name: 'free_users_page'
12 changes: 0 additions & 12 deletions app/views/admin/stats/_free_users_table.html.haml

This file was deleted.

28 changes: 14 additions & 14 deletions app/views/admin/stats/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,34 @@
.col-md-3
%strong All Users
.col-md-2
%strong #{format_number(@users.size)}
%strong #{format_number(@total_users)}
.row
.col-md-3
%strong Pro / Free
.col-md-2
%strong #{format_number(@users.pro_only.size)}
%span{style: "margin-left: 10px;"} #{number_to_percentage(@users.pro_only.size.to_f/@users.size.to_f*100, precision: 1)}
%strong #{format_number(@pro_users)}
%span{style: "margin-left: 10px;"} #{number_to_percentage(@pro_users.to_f/@total_users.to_f*100, precision: 1)}
.col-md-2
%strong #{format_number(@users.free_only.size)}
%strong #{format_number(@total_users - @pro_users)}
.row
.col-md-3
%strong Pro Monthly / Yearly / Forevers
.col-md-2
%strong #{format_number(@users.monthly.size)}
%strong #{format_number(@users.monthly)}
.col-md-2
%strong #{format_number(@users.yearly.size)}
%span{style: "margin-left: 10px;"} #{number_to_percentage(@users.yearly.size.to_f/@users.pro_only.size.to_f*100, precision: 1)}
%strong #{format_number(@users.yearly)}
%span{style: "margin-left: 10px;"} #{number_to_percentage(@users.yearly.to_f/@pro_users.to_f*100, precision: 1)}
.col-md-2
%strong #{format_number(@users.forever.size)}
%strong #{format_number(@users.forever)}
.row
.col-md-3
%strong Pro Stripe / Gumroad / Paypal
.col-md-2
%strong #{format_number(@users.payhere_only.size)}
%strong #{format_number(@users.payhere_only)}
.col-md-2
%strong #{format_number(@users.gumroad_only.size)}
%strong #{format_number(@users.gumroad_only)}
.col-md-2
%strong #{format_number(@users.paypal_only.size)}
%strong #{format_number(@users.paypal_only)}
.col-md-12
%hr
Expand All @@ -72,13 +72,13 @@
.col-md-3
%strong Referrals
.col-md-2
%strong #{format_number(@users.referrals.size)}
- @users.referrals.pluck(:referrer).uniq.each do |ref|
%strong #{format_number(@referral_users.size)}
- @referral_users.pluck(:referrer).uniq.each do |ref|
.row
.col-md-3
= ref
.col-md-2
#{format_number(@users.referrals.where(referrer: ref).size)}
#{format_number(@referral_users.where(referrer: ref).size)}
.col-md-12
%hr
Expand Down

0 comments on commit 453d6f9

Please sign in to comment.