From 6d4421432e987a10ee6d492dd4e40b1af30521ac Mon Sep 17 00:00:00 2001 From: kjgarza Date: Tue, 11 Feb 2020 17:47:32 +0100 Subject: [PATCH 1/2] log cursor to complete very long taks --- app/models/event.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/event.rb b/app/models/event.rb index 6c7db8c8a..c6e164534 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -549,6 +549,7 @@ def self.subj_id_check(options = {}) Rails.logger.warn "[DoubleCheck] DoubleCheck #{response.results.results.length} events starting with _id #{response.results.to_a.first[:_id]}." cursor = response.results.to_a.last[:sort] + Rails.logger.warn "[DoubleCheck] Cursor: #{cursor} " # dois = response.results.results.map(&:subj_id) events = response.results.results From f6727cc6c1160819b81cfbb66ab2a974a3582181 Mon Sep 17 00:00:00 2001 From: kjgarza Date: Wed, 12 Feb 2020 12:47:39 +0100 Subject: [PATCH 2/2] condition user stats --- app/controllers/dois_controller.rb | 2 ++ spec/requests/dois_spec.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/app/controllers/dois_controller.rb b/app/controllers/dois_controller.rb index a3569b8dc..b21b9ceb7 100644 --- a/app/controllers/dois_controller.rb +++ b/app/controllers/dois_controller.rb @@ -202,7 +202,9 @@ def index dois_names = results.map { |result| result.dig(:_source, :doi) }.join(',') metrics_array = get_metrics_array(dois_names) results = mix_in_metrics_array(results, metrics_array) + end + if params[:user_stats] person_metrics = get_person_metrics(params[:user_id]) citations = person_metrics[:citations] views = person_metrics[:views] diff --git a/spec/requests/dois_spec.rb b/spec/requests/dois_spec.rb index ebb68a0be..9e81c8ae5 100644 --- a/spec/requests/dois_spec.rb +++ b/spec/requests/dois_spec.rb @@ -136,6 +136,7 @@ let!(:doi) { create(:doi, client: client, aasm_state: "findable") } let!(:events) { create_list(:event_for_datacite_related, 3, obj_id: doi.doi) } let!(:views) { create_list(:event_for_datacite_usage, 2, obj_id: doi.doi, total: 25) } + let!(:orcid_event) { create(:event_for_datacite_orcid_auto_update, subj_id: doi.doi, obj_id:"https://orcid.org/0000-0003-1419-2405") } before do Event.import @@ -151,6 +152,7 @@ expect(json['data'].size).to eq(1) result = json.dig('data').select { |item| item["id"] == doi.doi.downcase }.first expect(json.dig('meta', 'total')).to eq(1) + expect(json.dig('meta', 'views')).to be_a(Array) expect(json.dig('data', 0, 'attributes', 'url')).to eq(doi.url) expect(json.dig('data', 0, 'attributes', 'doi')).to eq(doi.doi.downcase) expect(json.dig('data', 0, 'attributes', 'titles')).to eq(doi.titles) @@ -160,6 +162,16 @@ expect(json.dig('data', 0, 'attributes', 'viewsOverTime')).to eq([{"total"=>25, "year_month"=>"2015-06"}, {"total"=>25, "year_month"=>"2015-06"}]) end + it 'includes events with query parameter' do + get "/dois?mix-in=metrics&user-stats=true&user-id=0000-0003-1419-2405", nil, headers + + expect(last_response.status).to eq(200) + expect(json['data'].size).to eq(1) + result = json.dig('data').select { |item| item["id"] == doi.doi.downcase }.first + expect(json.dig('meta', 'total')).to eq(1) + expect(json.dig('meta', 'views')).to be > 0 + end + it 'includes events without query parameter' do get "/dois", nil, headers