Skip to content

Commit

Permalink
revert caching for metrics queries
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jan 11, 2020
1 parent 819dca8 commit 6dd301c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 69 deletions.
6 changes: 3 additions & 3 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
60 changes: 0 additions & 60 deletions app/models/concerns/cacheable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions app/queries/events_query.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

class EventsQuery
include Cacheable
include Facetable

ACTIVE_RELATION_TYPES = [
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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: [
Expand Down

0 comments on commit 6dd301c

Please sign in to comment.