From d7dd846186237db7cb97c5aefabe83bc03dde2f2 Mon Sep 17 00:00:00 2001 From: kjgarza Date: Tue, 6 Jul 2021 15:30:26 +0200 Subject: [PATCH 1/2] fix rake tasks for latests migrations changes --- db/seeds/development/base.seeds.rb | 2 +- lib/tasks/elasticsearch.rake | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/db/seeds/development/base.seeds.rb b/db/seeds/development/base.seeds.rb index fa545f939..b50cc1fd5 100644 --- a/db/seeds/development/base.seeds.rb +++ b/db/seeds/development/base.seeds.rb @@ -21,7 +21,7 @@ :client, provider: provider, symbol: ENV["MDS_USERNAME"], - password: ENV["MDS_PASSWORD"], + password_input: ENV["MDS_PASSWORD"], ) if Prefix.where(uid: "10.14454").blank? prefix = FactoryBot.create(:prefix, uid: "10.14454") diff --git a/lib/tasks/elasticsearch.rake b/lib/tasks/elasticsearch.rake index d8cfda6ef..1ac8ec86f 100644 --- a/lib/tasks/elasticsearch.rake +++ b/lib/tasks/elasticsearch.rake @@ -8,12 +8,29 @@ namespace :elasticsearch do fail "These tasks can only be used in the development enviroment" if Rails.env.production? Rake::Task["provider:create_index"].invoke + Rake::Task["provider:create_alias"].invoke + Rake::Task["client:create_index"].invoke + Rake::Task["client:create_alias"].invoke + Rake::Task["prefix:create_index"].invoke + Rake::Task["prefix:create_alias"].invoke + Rake::Task["provider_prefix:create_index"].invoke + Rake::Task["provider_prefix:create_alias"].invoke + Rake::Task["client_prefix:create_index"].invoke - Rake::Task["doi:create_index"].invoke + Rake::Task["client_prefix:create_alias"].invoke + + Rake::Task["other_doi:create_index"].invoke + Rake::Task["other_doi:create_alias"].invoke + + Rake::Task["datacite_doi:create_index"].invoke + Rake::Task["datacite_doi:create_alias"].invoke + Rake::Task["event:create_index"].invoke + Rake::Task["event:create_alias"].invoke + Rake::Task["activity:create_index"].invoke end @@ -26,6 +43,8 @@ namespace :elasticsearch do Rake::Task["prefix:delete_index"].invoke Rake::Task["provider_prefix:delete_index"].invoke Rake::Task["client_prefix:delete_index"].invoke + Rake::Task["other_doi:delete_index"].invoke + Rake::Task["datacite_doi:delete_index"].invoke Rake::Task["doi:delete_index"].invoke Rake::Task["event:delete_index"].invoke Rake::Task["activity:delete_index"].invoke From 120dffc7a11312e057af71e64b9c26f29e19267f Mon Sep 17 00:00:00 2001 From: kjgarza Date: Wed, 18 Aug 2021 14:50:00 +0200 Subject: [PATCH 2/2] store the aggregation results in a instance variable to avoid multiple request --- app/graphql/types/person_type.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/graphql/types/person_type.rb b/app/graphql/types/person_type.rb index a61820a42..8b9bcf7bb 100644 --- a/app/graphql/types/person_type.rb +++ b/app/graphql/types/person_type.rb @@ -182,20 +182,20 @@ def works(**args) def view_count args = { first: 0 } - r = response(args) - r.response.aggregations.view_count.value.to_i + @r = response(args) if @r.nil? + @r.response.aggregations.view_count.value.to_i end def download_count args = { first: 0 } - r = response(args) - r.response.aggregations.download_count.value.to_i + @r = response(args) if @r.nil? + @r.response.aggregations.download_count.value.to_i end def citation_count args = { first: 0 } - r = response(args) - r.response.aggregations.citation_count.value.to_i + @r = response(args) if @r.nil? + @r.response.aggregations.citation_count.value.to_i end def response(**args)