Followup 3657278da2 - Fixes #3257 - Data in DB and elasticsearch (e.g. ticket.

This commit is contained in:
Rolf Schmidt 2021-01-19 12:07:42 +01:00 committed by Thorsten Eckel
parent fdfb042398
commit 3ace03d79b
2 changed files with 5 additions and 5 deletions

View file

@ -16,7 +16,7 @@ class SearchIndexJob < ApplicationJob
@object = object
@o_id = o_id
record = @object.constantize.lookup(id: @o_id)
record = @object.constantize.find_by(id: @o_id)
return if !exists?(record)
update_search_index(record)
@ -31,7 +31,7 @@ class SearchIndexJob < ApplicationJob
def exists?(record)
return true if record
Rails.logger.info "Can't index #{@object}.lookup(id: #{@o_id}), no such record found"
Rails.logger.info "Can't index #{@object}.find_by(id: #{@o_id}), no such record found"
false
end
end

View file

@ -4,7 +4,7 @@ RSpec.describe SearchIndexJob, type: :job do
it 'calls search_index_update_backend on matching record' do
user = create(:user)
allow(::User).to receive(:lookup).with(id: user.id).and_return(user)
allow(::User).to receive(:find_by).with(id: user.id).and_return(user)
allow(user).to receive(:search_index_update_backend)
described_class.perform_now('User', user.id)
@ -13,7 +13,7 @@ RSpec.describe SearchIndexJob, type: :job do
it "doesn't perform for non existing records" do
id = 9999
allow(::User).to receive(:lookup).with(id: id).and_return(nil)
allow(::User).to receive(:find_by).with(id: id).and_return(nil)
allow(SearchIndexBackend).to receive(:add)
described_class.perform_now('User', id)
@ -21,7 +21,7 @@ RSpec.describe SearchIndexJob, type: :job do
end
it 'retries on exception' do
allow(::User).to receive(:lookup).and_raise(RuntimeError)
allow(::User).to receive(:find_by).and_raise(RuntimeError)
described_class.perform_now('User', 1)
expect(described_class).to have_been_enqueued