Skip to content

Commit

Permalink
disable metrics in api. #390
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Feb 15, 2020
1 parent c8326d2 commit 7dd4cb3
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 34 deletions.
12 changes: 6 additions & 6 deletions app/controllers/dois_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ def index
}
logger.warn method: "GET", path: "/dois", message: "AggregationsLinkChecks /dois", duration: bm

citations = total.positive? ? metric_facet_by_year(response.aggregations.citations.buckets) : nil
views = total.positive? ? metric_facet_by_year(response.aggregations.views.buckets) : nil
downloads = total.positive? ? metric_facet_by_year(response.aggregations.downloads.buckets) : nil
# citations = total.positive? ? metric_facet_by_year(response.aggregations.citations.buckets) : nil
# views = total.positive? ? metric_facet_by_year(response.aggregations.views.buckets) : nil
# downloads = total.positive? ? metric_facet_by_year(response.aggregations.downloads.buckets) : nil

respond_to do |format|
format.json do
Expand Down Expand Up @@ -229,9 +229,9 @@ def index
"linkChecksDcIdentifier" => link_checks_dc_identifier,
"linkChecksCitationDoi" => link_checks_citation_doi,
subjects: subjects,
citations: citations,
views: views,
downloads: downloads,
# citations: citations,
# views: views,
# downloads: downloads,
}.compact

options[:links] = {
Expand Down
2 changes: 1 addition & 1 deletion app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ def self.import_by_ids(options={})
end

def self.import_by_id(options={})
return nil unless options[:id].present?
return nil if options[:id].blank?

id = options[:id].to_i
index = if Rails.env.test?
Expand Down
10 changes: 5 additions & 5 deletions app/serializers/doi_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ class DoiSerializer
set_id :uid
# don't cache dois, as works are cached using the doi model

attributes :doi, :prefix, :suffix, :identifiers, :creators, :titles, :publisher, :container, :publication_year, :subjects, :contributors, :dates, :language, :types, :related_identifiers, :sizes, :formats, :version, :rights_list, :descriptions, :geo_locations, :funding_references, :xml, :url, :content_url, :metadata_version, :schema_version, :source, :is_active, :state, :reason, :landing_page, :view_count, :download_count, :reference_count, :citation_count, :part_count, :part_of_count, :version_count, :version_of_count, :views_over_time, :downloads_over_time, :created, :registered, :published, :updated
attributes :doi, :prefix, :suffix, :identifiers, :creators, :titles, :publisher, :container, :publication_year, :subjects, :contributors, :dates, :language, :types, :related_identifiers, :sizes, :formats, :version, :rights_list, :descriptions, :geo_locations, :funding_references, :xml, :url, :content_url, :metadata_version, :schema_version, :source, :is_active, :state, :reason, :landing_page, :created, :registered, :published, :updated
attributes :prefix, :suffix, if: Proc.new { |object, params| params && params[:detail] }

belongs_to :client, record_type: :clients
has_many :media, record_type: :media, id_method_name: :uid, if: Proc.new { |object, params| params && params[:detail] && !params[:is_collection]}
has_many :references, serializer: DoiSerializer, if: Proc.new { |object, params| params && params[:detail] }
has_many :citations, serializer: DoiSerializer, if: Proc.new { |object, params| params && params[:detail] }
has_many :parts, serializer: DoiSerializer, if: Proc.new { |object, params| params && params[:detail] }
has_many :versions, serializer: DoiSerializer, if: Proc.new { |object, params| params && params[:detail] }
# has_many :references, serializer: DoiSerializer, if: Proc.new { |object, params| params && params[:detail] }
# has_many :citations, serializer: DoiSerializer, if: Proc.new { |object, params| params && params[:detail] }
# has_many :parts, serializer: DoiSerializer, if: Proc.new { |object, params| params && params[:detail] }
# has_many :versions, serializer: DoiSerializer, if: Proc.new { |object, params| params && params[:detail] }

attribute :xml, if: Proc.new { |object, params| params && params[:detail] } do |object|
begin
Expand Down
44 changes: 22 additions & 22 deletions spec/requests/dois_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@

expect(result.dig('attributes', 'doi')).to eq(doi.doi.downcase)
expect(result.dig('attributes', 'titles')).to eq(doi.titles)
expect(result.dig('relationships','citations')).to eq("data"=>[])
expect(result.dig('relationships','references')).to eq("data"=>[])
# expect(result.dig('relationships','citations')).to eq("data"=>[])
# expect(result.dig('relationships','references')).to eq("data"=>[])
end
end

Expand Down Expand Up @@ -140,15 +140,15 @@
expect(last_response.status).to eq(200)
expect(json['data'].size).to eq(1)
expect(json.dig('meta', 'total')).to eq(1)
expect(json.dig('meta', 'views')).to eq([{"count"=>50, "id"=>"2011", "title"=>"2011"}])
expect(json.dig('meta', 'downloads')).to eq([{"count"=>20, "id"=>"2011", "title"=>"2011"}])
# expect(json.dig('meta', 'views')).to eq([{"count"=>50, "id"=>"2011", "title"=>"2011"}])
# expect(json.dig('meta', 'downloads')).to eq([{"count"=>20, "id"=>"2011", "title"=>"2011"}])
expect(json.dig('data', 0, 'attributes', 'publicationYear')).to eq(2011)
expect(json.dig('data', 0, 'attributes', 'doi')).to eq(doi.doi.downcase)
expect(json.dig('data', 0, 'attributes', 'titles')).to eq(doi.titles)
expect(json.dig('data', 0, 'attributes', 'viewCount')).to eq(50)
expect(json.dig('data', 0, 'attributes', 'viewsOverTime')).to eq([{"total"=>25, "yearMonth"=>"2015-06"}, {"total"=>25, "yearMonth"=>"2015-06"}])
expect(json.dig('data', 0, 'attributes', 'downloadCount')).to eq(20)
expect(json.dig('data', 0, 'attributes', 'downloadsOverTime')).to eq([{"total"=>10, "yearMonth"=>"2015-06"}, {"total"=>10, "yearMonth"=>"2015-06"}])
# expect(json.dig('data', 0, 'attributes', 'viewCount')).to eq(50)
# expect(json.dig('data', 0, 'attributes', 'viewsOverTime')).to eq([{"total"=>25, "yearMonth"=>"2015-06"}, {"total"=>25, "yearMonth"=>"2015-06"}])
# expect(json.dig('data', 0, 'attributes', 'downloadCount')).to eq(20)
# expect(json.dig('data', 0, 'attributes', 'downloadsOverTime')).to eq([{"total"=>10, "yearMonth"=>"2015-06"}, {"total"=>10, "yearMonth"=>"2015-06"}])

end
end
Expand All @@ -170,23 +170,23 @@
expect(json.dig('data', 'attributes', 'url')).to eq(doi.url)
expect(json.dig('data', 'attributes', 'doi')).to eq(doi.doi.downcase)
expect(json.dig('data', 'attributes', 'titles')).to eq(doi.titles)
expect(json.dig('data', 'attributes', 'viewCount')).to eq(75)
expect(json.dig('data', 'attributes', 'viewsOverTime')).to eq([{"total"=>25, "yearMonth"=>"2015-06"}, {"total"=>25, "yearMonth"=>"2015-06"}, {"total"=>25, "yearMonth"=>"2015-06"}])
# expect(json.dig('data', 'attributes', 'viewCount')).to eq(75)
# expect(json.dig('data', 'attributes', 'viewsOverTime')).to eq([{"total"=>25, "yearMonth"=>"2015-06"}, {"total"=>25, "yearMonth"=>"2015-06"}, {"total"=>25, "yearMonth"=>"2015-06"}])
end

it "has views meta" do
get "/dois", nil, headers

expect(last_response.status).to eq(200)
expect(json.dig('meta', 'views')).to eq([{"count"=>75, "id"=>"2011", "title"=>"2011"}])
# expect(json.dig('meta', 'views')).to eq([{"count"=>75, "id"=>"2011", "title"=>"2011"}])
end

it "repository shows summary count" do
get "/repositories/#{client.uid}", nil, headers

expect(last_response.status).to eq(200)
expect(json.dig('data', 'attributes', 'name')).to eq(client.name)
expect(json.dig('meta', 'views')).to eq([{"count"=>75, "id"=>"2011", "title"=>"2011"}])
# expect(json.dig('meta', 'views')).to eq([{"count"=>75, "id"=>"2011", "title"=>"2011"}])
end
end

Expand All @@ -207,15 +207,15 @@
expect(json.dig('data', 'attributes', 'url')).to eq(doi.url)
expect(json.dig('data', 'attributes', 'doi')).to eq(doi.doi.downcase)
expect(json.dig('data', 'attributes', 'titles')).to eq(doi.titles)
expect(json.dig('data', 'attributes', 'downloadCount')).to eq(30)
expect(json.dig('data', 'attributes', 'downloadsOverTime')).to eq([{"total"=>10, "yearMonth"=>"2015-06"}, {"total"=>10, "yearMonth"=>"2015-06"}, {"total"=>10, "yearMonth"=>"2015-06"}])
# expect(json.dig('data', 'attributes', 'downloadCount')).to eq(30)
# expect(json.dig('data', 'attributes', 'downloadsOverTime')).to eq([{"total"=>10, "yearMonth"=>"2015-06"}, {"total"=>10, "yearMonth"=>"2015-06"}, {"total"=>10, "yearMonth"=>"2015-06"}])
end

it "has downloads meta" do
get "/dois", nil, headers

expect(last_response.status).to eq(200)
expect(json.dig('meta', 'downloads')).to eq([{"count"=>30, "id"=>"2011", "title"=>"2011"}])
# expect(json.dig('meta', 'downloads')).to eq([{"count"=>30, "id"=>"2011", "title"=>"2011"}])
end

it "repository shows summary count" do
Expand Down Expand Up @@ -245,7 +245,7 @@
expect(json.dig('data', 'attributes', 'url')).to eq(doi.url)
expect(json.dig('data', 'attributes', 'doi')).to eq(doi.doi.downcase)
expect(json.dig('data', 'attributes', 'titles')).to eq(doi.titles)
expect(json.dig('data', 'attributes', 'referenceCount')).to eq(1)
# expect(json.dig('data', 'attributes', 'referenceCount')).to eq(1)
# expect(json.dig('data', 'relationships', 'references', 'data')).to eq(1)
# expect(json.dig('included').length).to eq(2)
# expect(json.dig('included', 1, 'attributes', 'relationTypeId')).to eq("references")
Expand All @@ -270,8 +270,8 @@
expect(json.dig('data', 'attributes', 'url')).to eq(doi.url)
expect(json.dig('data', 'attributes', 'doi')).to eq(doi.doi.downcase)
expect(json.dig('data', 'attributes', 'titles')).to eq(doi.titles)
expect(json.dig('data', 'attributes', 'citationCount')).to eq(1)
expect(json.dig('data', 'relationships', 'citations', 'data').length).to eq(1)
# expect(json.dig('data', 'attributes', 'citationCount')).to eq(1)
# expect(json.dig('data', 'relationships', 'citations', 'data').length).to eq(1)
# expect(json.dig('included').length).to eq(2)
# expect(json.dig('included', 0, 'attributes', 'doi')).to eq(source_doi.doi)
end
Expand All @@ -280,7 +280,7 @@
get "/dois", nil, headers

expect(last_response.status).to eq(200)
expect(json.dig('meta', 'citations')).to eq([{"count"=>1, "id"=>"2011", "title"=>"2011"}])
# expect(json.dig('meta', 'citations')).to eq([{"count"=>1, "id"=>"2011", "title"=>"2011"}])
end

it "repository shows summary count" do
Expand All @@ -289,7 +289,7 @@
puts last_response.body
expect(last_response.status).to eq(200)
expect(json.dig('data', 'attributes', 'name')).to eq(client.name)
expect(json.dig('meta', 'citations')).to eq([{"count"=>1, "id"=>"2011", "title"=>"2011"}])
# expect(json.dig('meta', 'citations')).to eq([{"count"=>1, "id"=>"2011", "title"=>"2011"}])
end
end

Expand All @@ -311,7 +311,7 @@
expect(json.dig('data', 'attributes', 'url')).to eq(doi.url)
expect(json.dig('data', 'attributes', 'doi')).to eq(doi.doi.downcase)
expect(json.dig('data', 'attributes', 'titles')).to eq(doi.titles)
expect(json.dig('data', 'attributes', 'partCount')).to eq(1)
# expect(json.dig('data', 'attributes', 'partCount')).to eq(1)
# expect(json.dig('data', 'relationships', 'parts', 'data')).to eq(1)
# expect(json.dig('included').length).to eq(2)
# expect(json.dig('included', 1, 'attributes', 'doi')).to eq(target_doi.doi)
Expand All @@ -337,7 +337,7 @@
expect(json.dig('data', 'attributes', 'url')).to eq(doi.url)
expect(json.dig('data', 'attributes', 'doi')).to eq(doi.doi.downcase)
expect(json.dig('data', 'attributes', 'titles')).to eq(doi.titles)
expect(json.dig('data', 'attributes', 'versionCount')).to eq(1)
# expect(json.dig('data', 'attributes', 'versionCount')).to eq(1)
# expect(json.dig('data', 'relationships', 'versions', 'data')).to eq(1)
# expect(json.dig('included').length).to eq(2)
# expect(json.dig('included', 1, 'attributes', 'doi')).to eq(target_doi.doi)
Expand Down

0 comments on commit 7dd4cb3

Please sign in to comment.