Skip to content

Commit

Permalink
fix cursor-based pagination. #233
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Apr 9, 2019
1 parent 7489629 commit 96a6c2c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/controllers/activities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/dois_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/works_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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])
Expand Down

0 comments on commit 96a6c2c

Please sign in to comment.