Skip to content

Commit

Permalink
Follow up 886cd32 - Revert after_commit changes because previous_chan…
Browse files Browse the repository at this point in the history
…ges hash is broken/empty by a bug when transaction/locks are used.
  • Loading branch information
rolfschmidt committed Nov 7, 2022
1 parent d879c67 commit afc7d23
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions app/models/concerns/has_search_index_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ module HasSearchIndexBackend
extend ActiveSupport::Concern

included do
after_commit :search_index_update, if: :persisted?
after_create :search_index_update
after_update :search_index_update
after_touch :search_index_update_touch
after_destroy :search_index_destroy
end

Expand All @@ -23,13 +25,32 @@ def search_index_update
# start background job to transfer data to search index
return true if !SearchIndexBackend.enabled?

return true if previous_changes.blank?
return true if saved_changes.blank?

SearchIndexJob.perform_later(self.class.to_s, id)
SearchIndexAssociationsJob.perform_later(self.class.to_s, id)
true
end

=begin
update search index, if configured - will be executed automatically
model = Model.find(123)
model.search_index_update_touch
=end

def search_index_update_touch
return true if ignore_search_indexing?(:update)

# start background job to transfer data to search index
return true if !SearchIndexBackend.enabled?

SearchIndexJob.perform_later(self.class.to_s, id)
true
end

def search_index_indexable
Models.indexable.reject { |local_class| local_class == self.class }
end
Expand Down

0 comments on commit afc7d23

Please sign in to comment.