Skip to content

Commit

Permalink
reintroduce cached doi_count
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Oct 23, 2018
1 parent bf80ff8 commit e8ccc58
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions app/models/concerns/cacheable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@ module Cacheable
extend ActiveSupport::Concern

included do
def cached_doi_count(options={})
Rails.cache.fetch("cached_doi_count/#{id}", expires_in: 24.hours, force: options[:force]) do
return [] if Rails.env.test?

if self.class.name == "Provider" && symbol != "ADMIN"
collection = Doi.joins(:client).where("datacentre.allocator = ?", id)
elsif self.class.name == "Client"
collection = Doi.where(datacentre: id)
else
collection = Doi
end

years = collection.order("YEAR(dataset.created)").group("YEAR(dataset.created)").count
years = years.map { |k,v| { id: k, title: k, count: v } }
end
end

def cached_metadata_count(options={})
Rails.cache.fetch("cached_metadata_count/#{id}", expires_in: 6.hours, force: options[:force]) do
return [] if Rails.env.test?
Expand Down Expand Up @@ -193,12 +210,5 @@ def cached_client_response(id, options={})
Client.where(symbol: id).first
end
end

def cached_clients_by_provider_response(id, options={})
Rails.cache.fetch("client_by_provider_response/#{id}", expires_in: 1.day) do
query = self.ds.where(is_active: true, allocator: id)
query.limit(25).offset(0).order(:name)
end
end
end
end

0 comments on commit e8ccc58

Please sign in to comment.