Skip to content

Commit

Permalink
don't use source_id for usage report events. #260
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed May 17, 2019
1 parent d697d5f commit ce9f5ce
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
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], source_id: "datacite-usage").dig(:meta, "total").to_i
Event.query(nil, subj_id: object.parent[:id]).dig(:meta, "total").to_i
end
end
9 changes: 8 additions & 1 deletion app/graphql/types/usage_report_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ class UsageReportType < BaseObject
end

def datasets(**args)
ids = Event.query(nil, subj_id: object[:id], source_id: "datacite-usage").fetch(:data, []).map do |e|
ids = Event.query(nil, subj_id: object[:id]).fetch(:data, []).map do |e|
doi_from_url(e[:obj_id])
end
ElasticsearchLoader.for(Doi).load_many(ids)
end

def doi_from_url(url)
if /\A(?:(http|https):\/\/(dx\.)?(doi.org|handle.test.datacite.org)\/)?(doi:)?(10\.\d{4,5}\/.+)\z/.match?(url)
uri = Addressable::URI.parse(url)
uri.path.gsub(/^\//, "").downcase
end
end
end

0 comments on commit ce9f5ce

Please sign in to comment.