Skip to content

Commit

Permalink
Merge pull request #239 from datacite/dois_perf_fixes
Browse files Browse the repository at this point in the history
Avoid using an instance variable for results.
  • Loading branch information
richardhallett authored Apr 12, 2019
2 parents c648f11 + 1d973ba commit 46e7254
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions app/controllers/dois_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ def index

respond_to do |format|
format.json do
@dois = results
options = {}
options[:meta] = {
total: total,
Expand All @@ -161,11 +160,11 @@ def index

options[:links] = {
self: request.original_url,
next: @dois.size < page[:size] ? nil : request.base_url + "/dois?" + {
next: results.size < page[:size] ? nil : request.base_url + "/dois?" + {
query: params[:query],
"provider-id" => params[:provider_id],
"client-id" => params[:client_id],
"page[cursor]" => page[:cursor].present? ? Array.wrap(@dois.to_a.last[:sort]).first : nil,
"page[cursor]" => page[:cursor].present? ? Array.wrap(results.to_a.last[:sort]).first : nil,
"page[number]" => page[:cursor].blank? && page[:number].present? ? page[:number] + 1 : nil,
"page[size]" => page[:size] }.compact.to_query
}.compact
Expand All @@ -176,7 +175,7 @@ def index
}

logger.info "[Benchmark] render " + Benchmark.ms {
render json: DoiSerializer.new(@dois, options).serialized_json, status: :ok
render json: DoiSerializer.new(results, options).serialized_json, status: :ok
}.to_s + " ms"
end
format.citation do
Expand Down Expand Up @@ -393,7 +392,7 @@ def get_dois
head :no_content and return unless client_prefix.present?

dois = Doi.get_dois(prefix: client_prefix.prefix, username: current_user.uid.upcase, password: current_user.password)
if dois.length > 0
if dois.length > 0
render json: { dois: dois }.to_json, status: :ok
else
head :no_content
Expand Down

0 comments on commit 46e7254

Please sign in to comment.