From e437c617e2a3f5b503b408c68e8b4fcc1c7ed42c Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Mon, 3 Feb 2020 11:38:34 +0100 Subject: [PATCH] easier updates of events. #390 --- app/models/concerns/indexable.rb | 11 +---------- app/models/event.rb | 9 +++++---- lib/tasks/event.rake | 2 +- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/app/models/concerns/indexable.rb b/app/models/concerns/indexable.rb index 56b5f44dc..479ada996 100644 --- a/app/models/concerns/indexable.rb +++ b/app/models/concerns/indexable.rb @@ -4,7 +4,7 @@ module Indexable require 'aws-sdk-sqs' included do - after_commit on: [:create] do + after_commit on: [:create, :update] do # use index_document instead of update_document to also update virtual attributes IndexJob.perform_later(self) if self.class.name == "Doi" @@ -20,15 +20,6 @@ module Indexable end end - after_commit on: [:update] do - # use index_document instead of update_document to also update virtual attributes - IndexJob.perform_later(self) - if self.class.name == "Doi" - update_column(:indexed, Time.zone.now) - send_import_message(self.to_jsonapi) if aasm_state == "findable" && !Rails.env.test? && !%w(crossref medra kisti jalc op).include?(client.symbol.downcase.split(".").first) - end - end - after_touch do # use index_document instead of update_document to also update virtual attributes IndexJob.perform_later(self) diff --git a/app/models/event.rb b/app/models/event.rb index e5ed19b49..82e77edf9 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -382,17 +382,18 @@ def self.update_crossref(options = {}) def self.update_target_doi(options = {}) size = (options[:size] || 1000).to_i cursor = (options[:cursor] || []) + target_relation_type_id = options[:target_relation_type_id] - response = Event.query(nil, target_doi: nil, page: { size: 1, cursor: [] }) - Rails.logger.info "[Update] #{response.results.total} events with no target_doi." + response = Event.query(nil, target_relation_type_id: target_relation_type_id, page: { size: 1, cursor: [] }) + Rails.logger.info "[Update] #{response.results.total} events with target_relation_type_id #{target_relation_type_id.to_s}." # walk through results using cursor if response.results.total > 0 while response.results.results.length > 0 do - response = Event.query(nil, target_doi: nil, page: { size: size, cursor: cursor }) + response = Event.query(nil, target_relation_type_id: target_relation_type_id, page: { size: size, cursor: cursor }) break unless response.results.results.length.positive? - Rails.logger.info "[Update] Updating #{response.results.results.length} events with no target_doi starting with _id #{response.results.to_a.first[:_id]}." + Rails.logger.info "[Update] Updating #{response.results.results.length} events with target_relation_type_id #{target_relation_type_id.to_s} starting with _id #{response.results.to_a.first[:_id]}." cursor = response.results.to_a.last[:sort] ids = response.results.results.map(&:uuid).uniq diff --git a/lib/tasks/event.rake b/lib/tasks/event.rake index 9a761968e..2271b7018 100644 --- a/lib/tasks/event.rake +++ b/lib/tasks/event.rake @@ -65,7 +65,7 @@ namespace :event do task :update_target_doi => :environment do cursor = ENV['CURSOR'].to_s.split(",") || [Event.minimum(:id), Event.minimum(:id)] - Event.update_target_doi(cursor: cursor, size: ENV['SIZE']) + Event.update_target_doi(cursor: cursor, target_relation_type_id: ENV['TARGET_RELATION_TYPE_ID'], size: ENV['SIZE']) end end