From 5d6a12843ec4b66ed0eecba89808d9bd45f18be8 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Wed, 20 Feb 2019 12:08:16 +0100 Subject: [PATCH] properly paginate results using cursor. #205 --- app/models/doi.rb | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/app/models/doi.rb b/app/models/doi.rb index d4fdd505f..2c57210b1 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -430,8 +430,9 @@ def self.import_by_day(options={}) while cursor > prev_cursor do response = Doi.query("created:[#{from_date.strftime("%F")} TO #{from_date.strftime("%F")}]", page: { size: 1000, cursor: cursor }) - prev_cursor = cursor + old_cursor = cursor cursor = Array.wrap(response.results.results.last.to_h[:sort]).first.to_i + prev__cursor = old_cursor response.records.each do |doi| begin @@ -486,8 +487,9 @@ def self.import_by_day_missing(options={}) while cursor > prev_cursor do response = Doi.query("-creators:* +created:[#{from_date.strftime("%F")} TO #{from_date.strftime("%F")}]", page: { size: 1000, cursor: cursor }) - prev_cursor = cursor + old_cursor = cursor cursor = Array.wrap(response.results.results.last.to_h[:sort]).first.to_i + prev_cursor = old_cursor response.records.each do |doi| begin @@ -824,8 +826,9 @@ def self.set_handle while cursor > prev_cursor do response = Doi.query("-registered:* +url:* -aasm_state:draft -provider_id:ethz -provider_id:europ", page: { size: 1000, cursor: cursor }) - prev_cursor = cursor + old_cursor = cursor cursor = Array.wrap(response.results.results.last.to_h[:sort]).first.to_i + prev_cursor = old_cursor response.results.results.each do |d| HandleJob.perform_later(d.doi) @@ -847,8 +850,9 @@ def self.set_url while cursor > prev_cursor do response = Doi.query("-url:* (+provider_id:ethz OR -aasm_status:draft)", page: { size: 1000, cursor: cursor }) - prev_cursor = cursor + old_cursor = cursor cursor = Array.wrap(response.results.results.last.to_h[:sort]).first.to_i + prev_cursor = old_cursor response.results.results.each do |d| UrlJob.perform_later(d.doi) @@ -870,9 +874,10 @@ def self.set_minted while cursor > prev_cursor do response = Doi.query("url:* +provider_id:ethz +aasm_state:draft", page: { size: 1000, cursor: cursor }) - prev_cursor = cursor + old_cursor = cursor cursor = Array.wrap(response.results.results.last.to_h[:sort]).first.to_i - + prev_cursor = old_cursor + response.results.results.each do |d| UrlJob.perform_later(d.doi) end @@ -896,7 +901,7 @@ def self.transfer(options={}) query = options[:query] || "*" response = Doi.query(query, client_id: options[:client_id], page: { size: 0, cursor: 1 }) - logger.info "#{response.results.total} DOIs found for client #{options[:client_id]}." + logger.info "[Transfer] #{response.results.total} DOIs found for client #{options[:client_id]}." if options[:client_id] && options[:target_id] && response.results.total > 0 # walk through results using cursor @@ -905,8 +910,9 @@ def self.transfer(options={}) while cursor > prev_cursor do response = Doi.query(query, client_id: options[:client_id], page: { size: 1000, cursor: cursor }) - prev_cursor = cursor + old_cursor = cursor cursor = Array.wrap(response.results.results.last.to_h[:sort]).first.to_i + prev_cursor = old_cursor response.results.results.each do |d| TransferJob.perform_later(d.doi, target_id: options[:target_id])