From 9434325724d5bebbd796b2a0515b7bf69037f864 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Wed, 24 Oct 2018 21:03:42 +0200 Subject: [PATCH] refactor doi indexing activerecord call --- app/models/doi.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/doi.rb b/app/models/doi.rb index 1932d9b6f..bf25e9f5b 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -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, @@ -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