From 8baead39965750b33d87d2d48a16cec009443315 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Sun, 9 Jun 2019 00:39:29 +0200 Subject: [PATCH] events are now accessed via elasticsearch --- app/graphql/types/dataset_type.rb | 2 +- .../types/dataset_usage_report_connection_with_meta_type.rb | 2 +- app/graphql/types/event_data_edge.rb | 2 +- .../types/funder_dataset_connection_with_meta_type.rb | 2 +- .../types/funder_publication_connection_with_meta_type.rb | 2 +- .../types/funder_software_connection_with_meta_type.rb | 2 +- app/graphql/types/funder_type.rb | 6 +++--- .../types/researcher_dataset_connection_with_meta_type.rb | 2 +- .../researcher_publication_connection_with_meta_type.rb | 2 +- .../types/researcher_software_connection_with_meta_type.rb | 2 +- app/graphql/types/researcher_type.rb | 6 +++--- .../types/usage_report_dataset_connection_with_meta_type.rb | 2 +- app/graphql/types/usage_report_type.rb | 2 +- 13 files changed, 17 insertions(+), 17 deletions(-) diff --git a/app/graphql/types/dataset_type.rb b/app/graphql/types/dataset_type.rb index 809ecee5e..39c021e22 100644 --- a/app/graphql/types/dataset_type.rb +++ b/app/graphql/types/dataset_type.rb @@ -8,7 +8,7 @@ class DatasetType < BaseObject end def usage_reports(**args) - ids = Event.query(nil, obj_id: object.id).fetch(:data, []).map do |e| + ids = Event.query(nil, obj_id: object.id).results.to_a.map do |e| e[:subj_id] end UsageReport.find_by_id(ids, page: { number: 1, size: args[:first] }).fetch(:data, []) diff --git a/app/graphql/types/dataset_usage_report_connection_with_meta_type.rb b/app/graphql/types/dataset_usage_report_connection_with_meta_type.rb index 340e38034..152110858 100644 --- a/app/graphql/types/dataset_usage_report_connection_with_meta_type.rb +++ b/app/graphql/types/dataset_usage_report_connection_with_meta_type.rb @@ -7,6 +7,6 @@ class DatasetUsageReportConnectionWithMetaType < BaseConnection field :total_count, Integer, null: false, cache: true def total_count - Event.query(nil, obj_id: object.parent.id).dig(:meta, "total").to_i + Event.query(nil, obj_id: object.parent.id).results.total end end diff --git a/app/graphql/types/event_data_edge.rb b/app/graphql/types/event_data_edge.rb index c7a340b66..8aa87598c 100644 --- a/app/graphql/types/event_data_edge.rb +++ b/app/graphql/types/event_data_edge.rb @@ -10,7 +10,7 @@ class EventDataEdge < GraphQL::Relay::Edge def event_data @event_data ||= begin - Event.query(nil, subj_id: self.node[:id], obj_id: self.parent[:id])[:data].first.to_h + Event.query(nil, subj_id: self.node[:id], obj_id: self.parent[:id]).results.first.to_h end end diff --git a/app/graphql/types/funder_dataset_connection_with_meta_type.rb b/app/graphql/types/funder_dataset_connection_with_meta_type.rb index f22768139..039294e7b 100644 --- a/app/graphql/types/funder_dataset_connection_with_meta_type.rb +++ b/app/graphql/types/funder_dataset_connection_with_meta_type.rb @@ -7,6 +7,6 @@ class FunderDatasetConnectionWithMetaType < BaseConnection field :total_count, Integer, null: false, cache: true def total_count - Event.query(nil, obj_id: object.parent[:id], citation_type: "Dataset-Funder").dig(:meta, "total").to_i + Event.query(nil, obj_id: object.parent[:id], citation_type: "Dataset-Funder").results.total end end diff --git a/app/graphql/types/funder_publication_connection_with_meta_type.rb b/app/graphql/types/funder_publication_connection_with_meta_type.rb index d176c4b7b..e414797e1 100644 --- a/app/graphql/types/funder_publication_connection_with_meta_type.rb +++ b/app/graphql/types/funder_publication_connection_with_meta_type.rb @@ -7,6 +7,6 @@ class FunderPublicationConnectionWithMetaType < BaseConnection field :total_count, Integer, null: false, cache: true def total_count - Event.query(nil, obj_id: object.parent[:id], citation_type: "Funder-JournalArticle").dig(:meta, "total").to_i + Event.query(nil, obj_id: object.parent[:id], citation_type: "Funder-JournalArticle").results.total end end diff --git a/app/graphql/types/funder_software_connection_with_meta_type.rb b/app/graphql/types/funder_software_connection_with_meta_type.rb index c29a4dd18..3f7a7f763 100644 --- a/app/graphql/types/funder_software_connection_with_meta_type.rb +++ b/app/graphql/types/funder_software_connection_with_meta_type.rb @@ -7,6 +7,6 @@ class FunderSoftwareConnectionWithMetaType < BaseConnection field :total_count, Integer, null: false, cache: true def total_count - Event.query(nil, obj_id: object.parent[:id], citation_type: "Funder-SoftwareSourceCode").dig(:meta, "total").to_i + Event.query(nil, obj_id: object.parent[:id], citation_type: "Funder-SoftwareSourceCode").results.total end end diff --git a/app/graphql/types/funder_type.rb b/app/graphql/types/funder_type.rb index 530be5b60..9536344b6 100644 --- a/app/graphql/types/funder_type.rb +++ b/app/graphql/types/funder_type.rb @@ -22,21 +22,21 @@ class FunderType < BaseObject end def datasets(**args) - ids = Event.query(nil, obj_id: object[:id], citation_type: "Dataset-Funder").fetch(:data, []).map do |e| + ids = Event.query(nil, obj_id: object[:id], citation_type: "Dataset-Funder").results.to_a.map do |e| doi_from_url(e[:subj_id]) end ElasticsearchLoader.for(Doi).load_many(ids) end def publications(**args) - ids = Event.query(nil, obj_id: object[:id], citation_type: "Funder-ScholarlyArticle").fetch(:data, []).map do |e| + ids = Event.query(nil, obj_id: object[:id], citation_type: "Funder-ScholarlyArticle").results.to_a.map do |e| doi_from_url(e[:subj_id]) end ElasticsearchLoader.for(Doi).load_many(ids) end def softwares(**args) - ids = Event.query(nil, obj_id: object[:id], citation_type: "Funder-SoftwareSourceCode").fetch(:data, []).map do |e| + ids = Event.query(nil, obj_id: object[:id], citation_type: "Funder-SoftwareSourceCode").results.to_a.map do |e| doi_from_url(e[:subj_id]) end ElasticsearchLoader.for(Doi).load_many(ids) diff --git a/app/graphql/types/researcher_dataset_connection_with_meta_type.rb b/app/graphql/types/researcher_dataset_connection_with_meta_type.rb index 4a47ec268..4b937afe0 100644 --- a/app/graphql/types/researcher_dataset_connection_with_meta_type.rb +++ b/app/graphql/types/researcher_dataset_connection_with_meta_type.rb @@ -7,7 +7,7 @@ class ResearcherDatasetConnectionWithMetaType < BaseConnection field :total_count, Integer, null: false, cache: true def total_count - Event.query(nil, obj_id: https_to_http(object.parent[:id]), citation_type: "Dataset-Person").dig(:meta, "total").to_i + Event.query(nil, obj_id: https_to_http(object.parent[:id]), citation_type: "Dataset-Person").results.total end def https_to_http(url) diff --git a/app/graphql/types/researcher_publication_connection_with_meta_type.rb b/app/graphql/types/researcher_publication_connection_with_meta_type.rb index f9508ea20..b10589ef9 100644 --- a/app/graphql/types/researcher_publication_connection_with_meta_type.rb +++ b/app/graphql/types/researcher_publication_connection_with_meta_type.rb @@ -7,7 +7,7 @@ class ResearcherPublicationConnectionWithMetaType < BaseConnection field :total_count, Integer, null: false, cache: true def total_count - Event.query(nil, obj_id: https_to_http(object.parent[:id]), citation_type: "Person-ScholarlyArticle").dig(:meta, "total").to_i + Event.query(nil, obj_id: https_to_http(object.parent[:id]), citation_type: "Person-ScholarlyArticle").results.total end def https_to_http(url) diff --git a/app/graphql/types/researcher_software_connection_with_meta_type.rb b/app/graphql/types/researcher_software_connection_with_meta_type.rb index 45765a7e9..2a95d0b1e 100644 --- a/app/graphql/types/researcher_software_connection_with_meta_type.rb +++ b/app/graphql/types/researcher_software_connection_with_meta_type.rb @@ -7,7 +7,7 @@ class ResearcherSoftwareConnectionWithMetaType < BaseConnection field :total_count, Integer, null: false, cache: true def total_count - Event.query(nil, obj_id: https_to_http(object.parent[:id]), citation_type: "Person-SoftwareSourceCode").dig(:meta, "total").to_i + Event.query(nil, obj_id: https_to_http(object.parent[:id]), citation_type: "Person-SoftwareSourceCode").results.total end def https_to_http(url) diff --git a/app/graphql/types/researcher_type.rb b/app/graphql/types/researcher_type.rb index b4a3c3104..c6b101272 100644 --- a/app/graphql/types/researcher_type.rb +++ b/app/graphql/types/researcher_type.rb @@ -26,21 +26,21 @@ def id end def datasets(**args) - ids = Event.query(nil, obj_id: https_to_http(object[:id]), citation_type: "Dataset-Person").fetch(:data, []).map do |e| + ids = Event.query(nil, obj_id: https_to_http(object[:id]), citation_type: "Dataset-Person").results.to_a.map do |e| doi_from_url(e[:subj_id]) end ElasticsearchLoader.for(Doi).load_many(ids) end def publications(**args) - ids = Event.query(nil, obj_id: https_to_http(object[:id]), citation_type: "Person-ScholarlyArticle").fetch(:data, []).map do |e| + ids = Event.query(nil, obj_id: https_to_http(object[:id]), citation_type: "Person-ScholarlyArticle").results.to_a.map do |e| doi_from_url(e[:subj_id]) end ElasticsearchLoader.for(Doi).load_many(ids) end def softwares(**args) - ids = Event.query(nil, obj_id: https_to_http(object[:id]), citation_type: "Person-SoftwareSourceCode").fetch(:data, []).map do |e| + ids = Event.query(nil, obj_id: https_to_http(object[:id]), citation_type: "Person-SoftwareSourceCode").results.to_a.map do |e| doi_from_url(e[:subj_id]) end ElasticsearchLoader.for(Doi).load_many(ids) diff --git a/app/graphql/types/usage_report_dataset_connection_with_meta_type.rb b/app/graphql/types/usage_report_dataset_connection_with_meta_type.rb index c4be0d4ed..85d8d4cd3 100644 --- a/app/graphql/types/usage_report_dataset_connection_with_meta_type.rb +++ b/app/graphql/types/usage_report_dataset_connection_with_meta_type.rb @@ -7,6 +7,6 @@ class UsageReportDatasetConnectionWithMetaType < BaseConnection field :total_count, Integer, null: false, cache: true def total_count - Event.query(nil, subj_id: object.parent[:id]).dig(:meta, "total").to_i + Event.query(nil, subj_id: object.parent[:id]).results.total end end diff --git a/app/graphql/types/usage_report_type.rb b/app/graphql/types/usage_report_type.rb index 056ff34a1..c4def59cb 100644 --- a/app/graphql/types/usage_report_type.rb +++ b/app/graphql/types/usage_report_type.rb @@ -12,7 +12,7 @@ class UsageReportType < BaseObject end def datasets(**args) - ids = Event.query(nil, subj_id: object[:id]).fetch(:data, []).map do |e| + ids = Event.query(nil, subj_id: object[:id]).results.to_a.map do |e| doi_from_url(e[:obj_id]) end ElasticsearchLoader.for(Doi).load_many(ids)