Skip to content

Commit

Permalink
Remove ai query for perf gains
Browse files Browse the repository at this point in the history
  • Loading branch information
parterburn committed Sep 4, 2024
1 parent 4e7a6b3 commit b7ae1dd
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 50 deletions.
50 changes: 25 additions & 25 deletions app/models/admin_stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,38 +78,38 @@ def users_created_since(date)
# User.free_only.where("created_at >= ?", date)
# end

# def upgraded_users_since(date)
# pro_users = []
# User.pro_only.includes(:payments).order("payments.created_at ASC").each do | user|
# first_payment = user.payments.order('payments.date').try(:first).try(:date)
# if first_payment.present? && first_payment > date
# pro_users << user
# end
# end
# pro_users
# end
def upgraded_users_since(date)
pro_users = []
User.pro_only.includes(:payments).order("payments.created_at ASC").each do | user|
first_payment = user.payments.order('payments.date').try(:first).try(:date)
if first_payment.present? && first_payment > date
pro_users << user
end
end
pro_users
end

# def bounced_users_since(date)
# User.where("emails_bounced > 0").where("updated_at >= ?", date)
# end

# def entries_per_day_for(user)
# (entry_count_for(user) / account_age_for(user).to_f).to_f.round(1)
# rescue ZeroDivisionError
# 0
# end
def entries_per_day_for(user)
(entry_count_for(user) / account_age_for(user).to_f).to_f.round(1)
rescue ZeroDivisionError
0
end

# def paid_status_for(user)
# entries_per_day = entries_per_day_for(user)
def paid_status_for(user)
entries_per_day = entries_per_day_for(user)

# if entry_count_for(user) == 0
# "danger"
# elsif entries_per_day <= 0.2
# "warning"
# else
# "great"
# end
# end
if entry_count_for(user) == 0
"danger"
elsif entries_per_day <= 0.2
"warning"
else
"great"
end
end

private

Expand Down
50 changes: 25 additions & 25 deletions app/views/admin/stats.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
=link_to admin_photos_path do
%strong #{format_number(photos_count)}
%span{style: "margin-left: 10px;"} #{number_to_percentage(photos_count.to_f/all_count.to_f*100, precision: 0)}
.row
.col-md-3
%strong All Entries using DabbleMeGPT
- ai_entries = all_entries.with_ai_responses
.col-md-2
%strong #{format_number(ai_entries.count)}
%span{style: "margin-left: 10px;"} #{format_number(ai_entries.pluck(:user_id).uniq.count)} users
-# .row
-# .col-md-3
-# %strong All Entries using DabbleMeGPT
-# - ai_entries = all_entries.with_ai_responses
-# .col-md-2
-# %strong #{format_number(ai_entries.count)}
-# %span{style: "margin-left: 10px;"} #{format_number(ai_entries.pluck(:user_id).uniq.count)} users
.col-md-12
%hr
Expand Down Expand Up @@ -132,24 +132,24 @@
= column_chart @dashboard.payments_by_month(1.year.ago), discrete: true
%br
-# .col-md-12
-# - upgrades = @dashboard.upgraded_users_since(90.days.ago)
-# %h3 #{pluralize(format_number(upgrades.count), "Upgrade")} from the last 90 days
-# %p
-# %table.table.table-striped.table-hover
-# %tr
-# %th Email
-# %th Upgraded
-# %th Paid
-# %th Entries
-# %th Per day
-# - upgrades.each do |user|
-# %tr{:class => @dashboard.paid_status_for(user)}
-# %td= user.email
-# %td= l(user.payments.first.date.to_date, format: :month_day)
-# %td= user.payments.sum(:amount)
-# %td= user.entries.count
-# %td= @dashboard.entries_per_day_for(user)
.col-md-12
- upgrades = @dashboard.upgraded_users_since(90.days.ago)
%h3 #{pluralize(format_number(upgrades.count), "Upgrade")} from the last 90 days
%p
%table.table.table-striped.table-hover
%tr
%th Email
%th Upgraded
%th Paid
%th Entries
%th Per day
- upgrades.each do |user|
%tr{:class => @dashboard.paid_status_for(user)}
%td= user.email
%td= l(user.payments.first.date.to_date, format: :month_day)
%td= user.payments.sum(:amount)
%td= user.entries.count
%td= @dashboard.entries_per_day_for(user)
-# .col-md-12
-# %hr
Expand Down

0 comments on commit b7ae1dd

Please sign in to comment.