From 3eb2b1d5748a6ca13c85f1100b9fef330f5d7897 Mon Sep 17 00:00:00 2001 From: Richard Hallett Date: Thu, 5 Nov 2020 12:01:02 +0100 Subject: [PATCH] Don't reindex on doi transfer if no db update --- app/jobs/transfer_job.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/jobs/transfer_job.rb b/app/jobs/transfer_job.rb index d37a0e080..8da3513ff 100644 --- a/app/jobs/transfer_job.rb +++ b/app/jobs/transfer_job.rb @@ -10,9 +10,13 @@ def perform(doi_id, options={}) doi = Doi.where(doi: doi_id).first if doi.present? && options[:client_target_id].present? - doi.update_attributes(datacentre: options[:client_target_id]) + # Success starts as true because update_attributes only returns false on error. + success = true + success = doi.update_attributes(datacentre: options[:client_target_id]) - doi.__elasticsearch__.index_document + if success + self.__elasticsearch__.index_document + end Rails.logger.info "[Transfer] Transferred DOI #{doi.doi}." elsif doi.present?