-
Notifications
You must be signed in to change notification settings - Fork 166
LG-15119 query optimization #11574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LG-15119 query optimization #11574
Changes from all commits
4a1c912
5789a55
7878906
635bde1
be510ef
fd04942
a19347c
49038c6
df40e9e
15761e9
fee6532
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,12 +48,12 @@ def agency_and_sp_emailable_report | |
| end | ||
|
|
||
| def active_agencies | ||
| @active_agencies ||= Agreements::PartnerAccountStatus.find_by(name: 'active'). | ||
| partner_accounts. | ||
| includes(:agency). | ||
| where('became_partner <= ?', report_date). | ||
| map(&:agency). | ||
| uniq | ||
| @active_agencies ||= Agency.joins(:partner_accounts). | ||
| where(partner_accounts: { | ||
| partner_account_status: Agreements::PartnerAccountStatus.find_by(name: 'active'), | ||
| became_partner: ..report_date, | ||
| }). | ||
| distinct | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this has a 2x speed improvement |
||
| end | ||
|
|
||
| def service_providers | ||
|
|
@@ -67,11 +67,12 @@ def service_providers | |
| end | ||
|
|
||
| def facial_match_issuers | ||
| @facial_match_issuers ||= Profile.where(active: true).where( | ||
| 'verified_at <= ?', | ||
| report_date.end_of_day, | ||
| ).where(idv_level: Profile::FACIAL_MATCH_IDV_LEVELS). | ||
| pluck(:initiating_service_provider_issuer).uniq | ||
| @facial_match_issuers ||= Reports::BaseReport.transaction_with_timeout do | ||
| Profile.active.facial_match_opt_in. | ||
| where('verified_at <= ?', report_date.end_of_day). | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, it can't be active without verified so idk why I am the way that I am. |
||
| distinct. | ||
| pluck(:initiating_service_provider_issuer) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,33 +83,30 @@ def total_user_count | |
|
|
||
| def verified_legacy_idv_user_count | ||
| Reports::BaseReport.transaction_with_timeout do | ||
| Profile.where(active: true).where( | ||
| 'verified_at <= ?', | ||
| end_date, | ||
| Profile.active.where( | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated most of this file to use the available class methods. |
||
| 'verified_at <= ?', end_date | ||
| ).count - verified_facial_match_user_count | ||
| end | ||
| end | ||
|
|
||
| def verified_facial_match_user_count | ||
| @verified_facial_match_user_count ||= Reports::BaseReport.transaction_with_timeout do | ||
| Profile.where(active: true).where( | ||
| 'verified_at <= ?', | ||
| end_date, | ||
| ).where(idv_level: Profile::FACIAL_MATCH_IDV_LEVELS).count | ||
| Profile.active.facial_match_opt_in.where( | ||
| 'verified_at <= ?', end_date | ||
| ).count | ||
| end | ||
| end | ||
|
|
||
| def new_verified_legacy_idv_user_count | ||
| Reports::BaseReport.transaction_with_timeout do | ||
| Profile.where(active: true).where(verified_at: current_month).count - | ||
| Profile.active.where(verified_at: current_month).count - | ||
| new_verified_facial_match_user_count | ||
| end | ||
| end | ||
|
|
||
| def new_verified_facial_match_user_count | ||
| @new_verified_facial_match_user_count ||= Reports::BaseReport.transaction_with_timeout do | ||
| Profile.where(active: true).where(verified_at: current_month). | ||
| where(idv_level: Profile::FACIAL_MATCH_IDV_LEVELS).count | ||
| Profile.active.facial_match_opt_in.where(verified_at: current_month).count | ||
| end | ||
| end | ||
|
|
||
|
|
@@ -121,15 +118,16 @@ def annual_total_user_count | |
|
|
||
| def annual_verified_legacy_idv_user_count | ||
| Reports::BaseReport.transaction_with_timeout do | ||
| Profile.where(active: true).where(verified_at: annual_start_date..annual_end_date).count - | ||
| Profile.active.where(verified_at: annual_start_date..annual_end_date).count - | ||
| annual_verified_facial_match_user_count | ||
| end | ||
| end | ||
|
|
||
| def annual_verified_facial_match_user_count | ||
| @annual_verified_facial_match_user_count ||= Reports::BaseReport.transaction_with_timeout do | ||
| Profile.where(active: true).where(verified_at: annual_start_date..annual_end_date). | ||
| where(idv_level: Profile::FACIAL_MATCH_IDV_LEVELS).count | ||
| Profile.active.facial_match_opt_in.where( | ||
| verified_at: annual_start_date..annual_end_date, | ||
| ).count | ||
| end | ||
| end | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| #!/usr/bin/env ruby | ||
| # frozen_string_literal: true | ||
|
|
||
| # | ||
| # This file was generated by Bundler. | ||
| # | ||
| # The application 'rspec' is installed as part of a gem, and | ||
| # this file is here to facilitate running it. | ||
| # | ||
|
|
||
| ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) | ||
|
|
||
| bundle_binstub = File.expand_path("bundle", __dir__) | ||
|
|
||
| if File.file?(bundle_binstub) | ||
| if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") | ||
| load(bundle_binstub) | ||
| else | ||
| abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. | ||
| Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") | ||
| end | ||
| end | ||
|
|
||
| require "rubygems" | ||
| require "bundler/setup" | ||
|
|
||
| load Gem.bin_path("rspec-core", "rspec") | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. helpful to not have to type 'bundle exec' |
||
Uh oh!
There was an error while loading. Please reload this page.