From 7dd4cb328b4c42669d7785417fecb20a63d27e64 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Sat, 15 Feb 2020 17:42:03 +0100 Subject: [PATCH] disable metrics in api. #390 --- app/controllers/dois_controller.rb | 12 ++++---- app/models/doi.rb | 2 +- app/serializers/doi_serializer.rb | 10 +++---- spec/requests/dois_spec.rb | 44 +++++++++++++++--------------- 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/app/controllers/dois_controller.rb b/app/controllers/dois_controller.rb index 010451041..3a465f67a 100644 --- a/app/controllers/dois_controller.rb +++ b/app/controllers/dois_controller.rb @@ -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 @@ -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] = { diff --git a/app/models/doi.rb b/app/models/doi.rb index 6732334ae..8b89ce446 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -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? diff --git a/app/serializers/doi_serializer.rb b/app/serializers/doi_serializer.rb index 50e42f1e9..899b9930e 100644 --- a/app/serializers/doi_serializer.rb +++ b/app/serializers/doi_serializer.rb @@ -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 diff --git a/spec/requests/dois_spec.rb b/spec/requests/dois_spec.rb index da2fb052f..e7db5ef74 100644 --- a/spec/requests/dois_spec.rb +++ b/spec/requests/dois_spec.rb @@ -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 @@ -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 @@ -170,15 +170,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', '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 @@ -186,7 +186,7 @@ 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 @@ -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 @@ -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") @@ -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 @@ -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 @@ -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 @@ -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) @@ -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)