Skip to content

Commit

Permalink
properly update prefix index from associations. #389
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Mar 23, 2020
1 parent a94b8d0 commit 3fb3357
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions app/models/concerns/indexable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ module Indexable
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.citations medra.citations jalc.citations kisti.citations op.citations).include?(client.symbol.downcase)
elsif ["Prefix", "ProviderPrefix", "ClientPrefix"].include?(self.class.name)
Rails.logger.info "#{self.class.name} #{uid} created or updated."
# reindex prefix, not triggered by standard callbacks
elsif ["ProviderPrefix", "ClientPrefix"].include?(self.class.name)
IndexJob.perform_later(self.prefix)
end
end

Expand All @@ -25,11 +26,16 @@ module Indexable
end
end

before_destroy do
after_commit on: [:destroy] do
begin
__elasticsearch__.delete_document
Rails.logger.warn "#{self.class.name} #{uid} deleted from Elasticsearch index."
# send_delete_message(self.to_jsonapi) if self.class.name == "Doi" && !Rails.env.test?

# reindex prefix
if ["ProviderPrefix", "ClientPrefix"].include?(self.class.name)
IndexJob.perform_later(self.prefix)
end
rescue Elasticsearch::Transport::Transport::Errors::NotFound => e
Rails.logger.error e.message
end
Expand Down

0 comments on commit 3fb3357

Please sign in to comment.