diff --git a/app/models/concerns/cacheable.rb b/app/models/concerns/cacheable.rb index bb1ac666c..e55ed0a28 100644 --- a/app/models/concerns/cacheable.rb +++ b/app/models/concerns/cacheable.rb @@ -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? @@ -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