From 96a6c2c113f349128d5700c1cd0a224522dbd45c Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Tue, 9 Apr 2019 17:12:40 +0200 Subject: [PATCH] fix cursor-based pagination. #233 --- app/controllers/activities_controller.rb | 2 +- app/controllers/dois_controller.rb | 2 +- app/controllers/works_controller.rb | 2 +- app/models/doi.rb | 14 +++++++------- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/controllers/activities_controller.rb b/app/controllers/activities_controller.rb index 7e72255bf..d8580d0a4 100644 --- a/app/controllers/activities_controller.rb +++ b/app/controllers/activities_controller.rb @@ -40,7 +40,7 @@ def index self: request.original_url, next: @activities.size < page[:size] ? nil : request.base_url + "/activities?" + { query: params[:query], - "page[cursor]" => page[:cursor].present? ? Array.wrap(@activities.last[:sort]).first : nil, + "page[cursor]" => page[:cursor].present? ? Array.wrap(@activities.to_a.last[:sort]).first : nil, "page[number]" => page[:cursor].blank? && page[:number].present? ? page[:number] + 1 : nil, "page[size]" => page[:size], sort: params[:sort] }.compact.to_query diff --git a/app/controllers/dois_controller.rb b/app/controllers/dois_controller.rb index d6765ad98..72a1fc7ec 100644 --- a/app/controllers/dois_controller.rb +++ b/app/controllers/dois_controller.rb @@ -163,7 +163,7 @@ def index query: params[:query], "provider-id" => params[:provider_id], "client-id" => params[:client_id], - "page[cursor]" => page[:cursor].present? ? Array.wrap(@dois.last[:sort]).first : nil, + "page[cursor]" => page[:cursor].present? ? Array.wrap(@dois.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 diff --git a/app/controllers/works_controller.rb b/app/controllers/works_controller.rb index 5481e78ac..581a990a5 100644 --- a/app/controllers/works_controller.rb +++ b/app/controllers/works_controller.rb @@ -76,7 +76,7 @@ def index query: params[:query], "member-id" => params[:provider_id], "data-center-id" => params[:client_id], - "page[cursor]" => page[:cursor].present? ? Array.wrap(@dois.last[:sort]).first : nil, + "page[cursor]" => page[:cursor].present? ? Array.wrap(@dois.to_a.last[:sort]).first : nil, "page[size]" => page[:size] }.compact.to_query }.compact options[:include] = @include diff --git a/app/models/doi.rb b/app/models/doi.rb index dc5c9fe00..245cfd54e 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -430,7 +430,7 @@ def self.import_missing_by_empty_attribute(options={}) break unless response.results.results.length > 0 logger.info "[Metadata Missing Fix] Attempting fix for #{response.results.results.length} DOIs starting with _id #{cursor + 1}." - cursor = response.results.results.last[:sort].first.to_i + cursor = response.results.to_a.last[:sort].first.to_i response.results.results.each do |d| # Import One as a background job @@ -476,7 +476,7 @@ def self.import_by_day(options={}) break unless response.results.results.length > 0 logger.info "[MySQL] Importing metadata for #{response.results.results.length} DOIs starting with _id #{cursor + 1}." - cursor = response.results.results.last[:sort].first.to_i + cursor = response.results.to_a.last[:sort].first.to_i response.records.each do |doi| begin @@ -533,7 +533,7 @@ def self.import_by_day_missing(options={}) break unless response.results.results.length > 0 logger.info "[MySQL] Importing missing metadata for #{response.results.results.length} DOIs starting with _id #{cursor + 1}." - cursor = response.results.results.last[:sort].first.to_i + cursor = response.results.to_a.last[:sort].first.to_i response.records.each do |doi| begin @@ -888,7 +888,7 @@ def self.set_handle break unless response.results.results.length > 0 logger.info "[Handle] Register #{response.results.results.length} DOIs in the handle system starting with _id #{cursor + 1}." - cursor = response.results.results.last[:sort].first.to_i + cursor = response.results.to_a.last[:sort].first.to_i response.results.results.each do |d| HandleJob.perform_later(d.doi) @@ -912,7 +912,7 @@ def self.set_url break unless response.results.results.length > 0 logger.info "[Handle] Update URL for #{response.results.results.length} DOIs starting with _id #{cursor + 1}." - cursor = response.results.results.last[:sort].first.to_i + cursor = response.results.to_a.last[:sort].first.to_i response.results.results.each do |d| UrlJob.perform_later(d.doi) @@ -936,7 +936,7 @@ def self.set_minted break unless response.results.results.length > 0 logger.info "[MySQL] Set minted for #{response.results.results.length} DOIs starting with _id #{cursor + 1}." - cursor = response.results.results.last[:sort].first.to_i + cursor = response.results.to_a.last[:sort].first.to_i response.results.results.each do |d| UrlJob.perform_later(d.doi) @@ -973,7 +973,7 @@ def self.transfer(options={}) break unless response.results.results.length > 0 logger.info "[Transfer] Transferring #{response.results.results.length} DOIs starting with _id #{cursor + 1}." - cursor = response.results.results.last[:sort].first.to_i + cursor = response.results.to_a.last[:sort].first.to_i response.results.results.each do |d| TransferJob.perform_later(d.doi, target_id: options[:target_id])