Browse Source

Revert "Follow up 886cd320c8bced0b48c1992ce2bf8b383ef149f9 - Revert after_commit changes because previous_changes hash is broken/empty by a bug when transaction/locks are used."

Rolf Schmidt 2 years ago
parent
commit
7259e9f14f
1 changed files with 2 additions and 23 deletions
  1. 2 23
      app/models/concerns/has_search_index_backend.rb

+ 2 - 23
app/models/concerns/has_search_index_backend.rb

@@ -4,9 +4,7 @@ module HasSearchIndexBackend
   extend ActiveSupport::Concern
 
   included do
-    after_create  :search_index_update
-    after_update  :search_index_update
-    after_touch   :search_index_update_touch
+    after_commit  :search_index_update, if: :persisted?
     after_destroy :search_index_destroy
   end
 
@@ -25,32 +23,13 @@ update search index, if configured - will be executed automatically
     # start background job to transfer data to search index
     return true if !SearchIndexBackend.enabled?
 
-    return true if saved_changes.blank?
+    return true if previous_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