Skip to content

Commit

Permalink
easier updates of events. #390
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Feb 3, 2020
1 parent a664a6e commit e437c61
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
11 changes: 1 addition & 10 deletions app/models/concerns/indexable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/event.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit e437c61

Please sign in to comment.