diff --git a/app/controllers/works_controller.rb b/app/controllers/works_controller.rb index 4e86842b2..a01de2e50 100644 --- a/app/controllers/works_controller.rb +++ b/app/controllers/works_controller.rb @@ -140,17 +140,25 @@ def show protected def set_doi - @doi = nil - bm = Benchmark.ms { - options = filter_doi_by_role(current_user) - response = Doi.find_by_id(params[:id], options) - @doi = response.results.first - } - - fail ActiveRecord::RecordNotFound unless @doi.present? - logger = LogStashLogger.new(type: :stdout) - logger.warn method: "GET", path: "/works/#{@doi.doi}", message: "Request /works/#{@doi.doi}", duration: bm + + @doi = nil + + if rand(2) == 0 + bm = Benchmark.ms { + @doi = Doi.where(doi: params[:id], aasm_state: "findable").first + } + fail ActiveRecord::RecordNotFound unless @doi.present? + logger.warn method: "GET", path: "/works/#{@doi.doi}", message: "Request DB /works/#{@doi.doi}", duration: bm + else + bm = Benchmark.ms { + options = filter_doi_by_role(current_user) + response = Doi.find_by_id(params[:id], options) + @doi = response.results.first + } + fail ActiveRecord::RecordNotFound unless @doi.present? + logger.warn method: "GET", path: "/works/#{@doi.doi}", message: "Request ES /works/#{@doi.doi}", duration: bm + end end def set_include