diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index eacfbb58c..e6881e75f 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -145,12 +145,12 @@ def index dois_usage = total.positive? ? EventsQuery.new.usage(params[:doi]) : nil # dois_citations = total.positive? && aggregations.blank? || aggregations.include?("query_aggregations") ? facet_citations_by_year_v1(response.response.aggregations.dois_citations) : nil citations = total.positive? ? EventsQuery.new.citations(params[:doi]) : nil - citations_histogram = total.positive? ? cached_citations_histogram_response(params[:doi]) : nil + citations_histogram = total.positive? ? EventsQuery.new.citations_histogram(params[:doi]) : nil references = total.positive? && aggregations.include?("citations_aggregations") ? facet_citations_by_dois(response.response.aggregations.references.dois.buckets) : nil relations = total.positive? && aggregations.include?("citations_aggregations") ? facet_citations_by_dois(response.response.aggregations.relations.dois.buckets) : nil - views_histogram = total.positive? ? cached_views_histogram_response(params[:doi]) : nil - downloads_histogram = total.positive? ? cached_downloads_histogram_response(params[:doi]) : nil + views_histogram = total.positive? ? EventsQuery.new.views_histogram(params[:doi]) : nil + downloads_histogram = total.positive? ? EventsQuery.new.downloads_histogram(params[:doi]) : nil # views = total.positive? ? EventsQuery.new.views(params[:doi]) : nil # downloads = total.positive? ? EventsQuery.new.downloads(params[:doi]) : nil diff --git a/app/models/concerns/cacheable.rb b/app/models/concerns/cacheable.rb index 4f390d94c..d48f9cb1e 100644 --- a/app/models/concerns/cacheable.rb +++ b/app/models/concerns/cacheable.rb @@ -67,66 +67,6 @@ def cached_alb_public_key(kid) response.body.fetch("data", nil) end end - - def cached_doi_citations_response(doi) - if Rails.application.config.action_controller.perform_caching - Rails.cache.fetch("cached_doi_citations_response/#{doi}", expires_in: 24.hours) do - EventsQuery.new.doi_citations(doi) - end - else - EventsQuery.new.doi_citations(doi) - end - end - - def cached_doi_views_response(doi) - if Rails.application.config.action_controller.perform_caching - Rails.cache.fetch("cached_doi_views_response/#{doi}", expires_in: 24.hours) do - EventsQuery.new.doi_views(doi) - end - else - EventsQuery.new.doi_views(doi) - end - end - - def cached_doi_downloads_response(doi) - if Rails.application.config.action_controller.perform_caching - Rails.cache.fetch("cached_doi_downloads_response/#{doi}", expires_in: 24.hours) do - EventsQuery.new.doi_downloads(doi) - end - else - EventsQuery.new.doi_downloads(doi) - end - end - - def cached_citations_histogram_response(doi) - if Rails.application.config.action_controller.perform_caching - Rails.cache.fetch("cached_citations_histogram_response/#{doi}", expires_in: 24.hours) do - EventsQuery.new.citations_histogram(doi) - end - else - EventsQuery.new.citations_histogram(doi) - end - end - - def cached_views_histogram_response(doi) - if Rails.application.config.action_controller.perform_caching - Rails.cache.fetch("cached_views_histogram_response/#{doi}", expires_in: 24.hours) do - EventsQuery.new.views_histogram(doi) - end - else - EventsQuery.new.views_histogram(doi) - end - end - - def cached_downloads_histogram_response(doi) - if Rails.application.config.action_controller.perform_caching - Rails.cache.fetch("cached_downloads_histogram_response/#{doi}", expires_in: 24.hours) do - EventsQuery.new.downloads_histogram(doi) - end - else - EventsQuery.new.downloads_histogram(doi) - end - end end module ClassMethods diff --git a/app/queries/events_query.rb b/app/queries/events_query.rb index b720e5c31..0018fb7b4 100644 --- a/app/queries/events_query.rb +++ b/app/queries/events_query.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true class EventsQuery - include Cacheable include Facetable ACTIVE_RELATION_TYPES = [ @@ -30,7 +29,7 @@ def doi_citations(doi) def citations(doi) return {} unless doi.present? doi.downcase.split(",").map do |item| - { id: item, count: cached_doi_citations_response(item) } + { id: item, count: EventsQuery.new.doi_citations(item) } end end @@ -53,7 +52,7 @@ def doi_views(doi) def views(doi) return {} unless doi.present? doi.downcase.split(",").map do |item| - { id: item, count: cached_doi_views_response(item) } + { id: item, count: EventsQuery.new.doi_views(item) } end end @@ -75,7 +74,7 @@ def doi_downloads(doi) def downloads(doi) return {} unless doi.present? doi.downcase.split(",").map do |item| - { id: item, count: cached_doi_downloads_response(item) } + { id: item, count: EventsQuery.new.doi_downloads(item) } end end @@ -91,8 +90,8 @@ def usage(doi) return {} unless doi.present? doi.downcase.split(",").map do |item| pid = Event.new.normalize_doi(item) - requests = cached_doi_downloads_response(item) - investigations = cached_doi_views_response(item) + requests = EventsQuery.new.doi_downloads(item) + investigations = EventsQuery.new.doi_views(item) { id: pid, title: pid, relationTypes: [