Skip to content

Commit

Permalink
[LG-12819] Optimized proofing query (#11083)
Browse files Browse the repository at this point in the history
* updated proofing query \n
changelog Internal, Proofing Metrics, optimized proofing query

* Update spec/lib/reporting/fraud_metrics_lg99_report_spec.rb

Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>

* changelog Internal, Proofing Metrics, optimized proofing query

* changelog: Internal, Proofing Metrics, optimized proofing query

---------

Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>
  • Loading branch information
MrNagoo and zachmargolis authored Aug 15, 2024
1 parent 604aa3c commit 6ab79b3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 4 additions & 5 deletions lib/reporting/fraud_metrics_lg99_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,16 @@ def user_days_to_suspension_avg
end

def user_days_proofed_to_suspension_avg
user_data = User.where(uuid: data[Events::SUSPENDED_USERS]).joins(:profiles).
where.not(profiles: { verified_at: nil }).
group('users.id').
user_data = User.where(uuid: data[Events::SUSPENDED_USERS]).includes(:profiles).
merge(Profile.active).
pluck(
'MAX(profiles.verified_at)',
:activated_at,
:suspended_at,
)

return 'n/a' if user_data.empty?

difference = user_data.map { |profiled_at, suspended_at| suspended_at - profiled_at }
difference = user_data.map { |activated_at, suspended_at| suspended_at - activated_at }
(difference.sum / difference.size).seconds.in_days.round(2)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/reporting/fraud_metrics_lg99_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
{ 'user_id' => 'user7', 'name' => 'User Suspension: Suspended' },
],
)
user7&.profiles&.verified&.last&.update(created_at: 1.day.ago, verified_at: 1.day.ago)
user7.profiles.verified.last.update(created_at: 1.day.ago, activated_at: 1.day.ago) if user7
end

describe '#lg99_metrics_table' do
Expand Down

0 comments on commit 6ab79b3

Please sign in to comment.