Skip to content

Commit

Permalink
events are now accessed via elasticsearch
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jun 8, 2019
1 parent cb9ae87 commit 8baead3
Show file tree
Hide file tree
Showing 13 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/graphql/types/dataset_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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, [])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion app/graphql/types/event_data_edge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions app/graphql/types/funder_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions app/graphql/types/researcher_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion app/graphql/types/usage_report_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8baead3

Please sign in to comment.