Skip to content

Commit

Permalink
improve performance of client_totals method. #224
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Apr 9, 2019
1 parent c605ed6 commit 414c071
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 42 deletions.
22 changes: 6 additions & 16 deletions app/controllers/concerns/facetable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,7 @@ def facet_by_provider(arr)
end

def providers_totals(arr)
# generate hash with id and name for each provider in facet

ids = arr.map { |hsh| hsh["key"] }.join(",")
providers = Provider.find_by_ids(ids, size: 1000).records.pluck(:symbol, :name).to_h
providers = Provider.all.pluck(:symbol, :name).to_h

arr.map do |hsh|
{ "id" => hsh["key"],
Expand All @@ -117,16 +114,15 @@ def providers_totals(arr)
end

def prefixes_totals(arr)
# generate hash with id and name for each provider in facet

arr.map do |hsh|
{ "id" => hsh["key"],
"title" => hsh["key"],
"count" => hsh["doc_count"],
"temporal" => {
"this_month" => facet_anual(hsh.this_month.buckets),
"this_year" => facet_anual(hsh.this_year.buckets),
"last_year" => facet_anual(hsh.last_year.buckets)},
"this_month" => facet_anual(hsh.this_month.buckets),
"this_year" => facet_anual(hsh.this_year.buckets),
"last_year" => facet_anual(hsh.last_year.buckets)
},
"states" => facet_by_key(hsh.states.buckets)
}
end
Expand All @@ -136,15 +132,9 @@ def prefixes_totals(arr)
def clients_totals(arr)
logger = Logger.new(STDOUT)

# generate hash with id and name for each client in facet
ids = nil
logger.info "[Benchmark] clients_totals ids " + Benchmark.ms {
ids = arr.map { |hsh| hsh["key"] }.join(",")
}.to_s + " ms"

clients = nil
logger.info "[Benchmark] clients_totals find_by_ids " + Benchmark.ms {
clients = Client.find_by_ids(ids, size: 2000).records.pluck(:symbol, :name).to_h
clients = Client.all.pluck(:symbol, :name).to_h
}.to_s + " ms"

logger.info "[Benchmark] clients_totals map " + Benchmark.ms {
Expand Down
50 changes: 24 additions & 26 deletions app/controllers/dois_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,32 +46,30 @@ def index
elsif params[:ids].present?
response = Doi.find_by_ids(params[:ids], page: page, sort: sort)
else
logger.info "[Benchmark] query " + Benchmark.ms {
response = Doi.query(params[:query],
state: params[:state],
created: params[:created],
registered: params[:registered],
provider_id: params[:provider_id],
client_id: params[:client_id],
prefix: params[:prefix],
person_id: params[:person_id],
resource_type_id: params[:resource_type_id],
schema_version: params[:schema_version],
subject: params[:subject],
link_check_status: params[:link_check_status],
link_check_has_schema_org: params[:link_check_has_schema_org],
link_check_body_has_pid: params[:link_check_body_has_pid],
link_check_found_schema_org_id: params[:link_check_found_schema_org_id],
link_check_found_dc_identifier: params[:link_check_found_dc_identifier],
link_check_found_citation_doi: params[:link_check_found_citation_doi],
link_check_redirect_count_gte: params[:link_check_redirect_count_gte],
sample_group: sample_group_field,
sample_size: params[:sample],
source: params[:source],
page: page,
sort: sort,
random: params[:random])
}.to_s + " ms"
response = Doi.query(params[:query],
state: params[:state],
created: params[:created],
registered: params[:registered],
provider_id: params[:provider_id],
client_id: params[:client_id],
prefix: params[:prefix],
person_id: params[:person_id],
resource_type_id: params[:resource_type_id],
schema_version: params[:schema_version],
subject: params[:subject],
link_check_status: params[:link_check_status],
link_check_has_schema_org: params[:link_check_has_schema_org],
link_check_body_has_pid: params[:link_check_body_has_pid],
link_check_found_schema_org_id: params[:link_check_found_schema_org_id],
link_check_found_dc_identifier: params[:link_check_found_dc_identifier],
link_check_found_citation_doi: params[:link_check_found_citation_doi],
link_check_redirect_count_gte: params[:link_check_redirect_count_gte],
sample_group: sample_group_field,
sample_size: params[:sample],
source: params[:source],
page: page,
sort: sort,
random: params[:random])
end

begin
Expand Down

0 comments on commit 414c071

Please sign in to comment.