Skip to content

Commit

Permalink
refactor doi indexing activerecord call
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Oct 24, 2018
1 parent 9187b93 commit 9434325
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,14 @@ def self.index(options={})

def self.index_by_day(options={})
return nil unless options[:from_date].present?
from_date = Date.parse(options[:from_date])

errors = 0
count = 0

logger = Logger.new(STDOUT)

Doi.where(created: [options[:from_date] + " 00:00:00", options[:from_date] + " 23:59:59"]).not_indexed.find_in_batches(batch_size: 500) do |dois|
Doi.where(created: from_date.midnight..from_date.end_of_day).not_indexed.find_in_batches(batch_size: 500) do |dois|
response = Doi.__elasticsearch__.client.bulk \
index: Doi.index_name,
type: Doi.document_type,
Expand All @@ -268,7 +269,7 @@ def self.index_by_day(options={})

count = 0

Doi.where(created: [options[:from_date] + " 00:00:00", options[:from_date] + " 23:59:59"]).not_indexed.find_each do |doi|
Doi.where(created: from_date.midnight..from_date.end_of_day).not_indexed.find_each do |doi|
IndexJob.perform_later(doi)
doi.update_column(:indexed, Time.zone.now)
count += 1
Expand Down

0 comments on commit 9434325

Please sign in to comment.