Browse Source

Fixes #4306 - Updating group settings causes huge numbers of delayed jobs.

Rolf Schmidt 2 years ago
parent
commit
4d81950ddf

+ 1 - 15
app/models/concerns/has_search_index_backend.rb

@@ -62,16 +62,6 @@ update search index, if configured - will be executed automatically
     result
   end
 
-  def search_index_indexable_bulk_updates?(index_class)
-    SearchIndexBackend.get_mapping_properties_object(index_class).dig(:_source, :excludes).blank?
-  end
-
-  def search_index_update_full(index_class:, attribute:)
-    index_class.select('id').where(attribute[:name] => id).order(id: :desc).limit(10_000).pluck(:id).each do |row_id|
-      SearchIndexJob.perform_later(index_class.to_s, row_id)
-    end
-  end
-
   def search_index_update_delta(index_class:, value:, attribute:)
     data = {
       attribute[:ref_name] => value,
@@ -106,11 +96,7 @@ returns
 
     search_index_indexable.each do |index_class|
       search_index_indexable_attributes(index_class).each do |attribute|
-        if search_index_indexable_bulk_updates?(index_class)
-          search_index_update_delta(index_class: index_class, value: new_search_index_value, attribute: attribute)
-        else
-          search_index_update_full(index_class: index_class, attribute: attribute)
-        end
+        search_index_update_delta(index_class: index_class, value: new_search_index_value, attribute: attribute)
       end
     end
 

+ 11 - 0
db/migrate/20221111124620_issue4306_delete_setting.rb

@@ -0,0 +1,11 @@
+# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
+
+class Issue4306DeleteSetting < ActiveRecord::Migration[6.1]
+  def change
+
+    # return if it's a new setup
+    return if !Setting.exists?(name: 'system_init_done')
+
+    Setting.find_by(name: 'es_excludes').destroy
+  end
+end

+ 0 - 9
db/seeds/settings.rb

@@ -3164,15 +3164,6 @@ Setting.create_if_not_exists(
   preferences: { online_service_disable: true },
   frontend:    false
 )
-Setting.create_if_not_exists(
-  title:       __('Elasticsearch Excludes'),
-  name:        'es_excludes',
-  area:        'SearchIndex::Elasticsearch',
-  description: __('Defines if the search index is using excluded attributes.'),
-  state:       true,
-  preferences: { online_service_disable: true },
-  frontend:    false
-)
 
 Setting.create_if_not_exists(
   title:       __('Import Mode'),

+ 0 - 8
i18n/zammad.pot

@@ -3084,10 +3084,6 @@ msgstr ""
 msgid "Defines if the i-doit (https://www.i-doit.org/) integration is enabled or not."
 msgstr ""
 
-#: db/seeds/settings.rb
-msgid "Defines if the search index is using excluded attributes."
-msgstr ""
-
 #: db/seeds/settings.rb
 msgid "Defines if tickets can be created via web form."
 msgstr ""
@@ -3852,10 +3848,6 @@ msgstr ""
 msgid "Elasticsearch Endpoint User"
 msgstr ""
 
-#: db/seeds/settings.rb
-msgid "Elasticsearch Excludes"
-msgstr ""
-
 #: db/seeds/settings.rb
 msgid "Elasticsearch Pipeline Name"
 msgstr ""

+ 0 - 15
lib/search_index_backend.rb

@@ -1082,25 +1082,10 @@ helper method for making HTTP calls and raising error if response was not succes
 
     case object.name
     when 'Ticket'
-      result[name][:_source] = {
-        excludes: ['article.attachment']
-      }
       result[name][:properties][:article] = {
         type:              'nested',
         include_in_parent: true,
       }
-    when 'KnowledgeBase::Answer::Translation'
-      result[name][:_source] = {
-        excludes: ['attachment']
-      }
-    end
-
-    if !Setting.get('es_excludes')
-      result.each_key do |key|
-        next if !result[key][:_source]
-
-        result[key][:_source].delete(:excludes)
-      end
     end
 
     result[name]

+ 0 - 4
spec/models/ticket/has_search_index_backend_spec.rb

@@ -69,10 +69,6 @@ RSpec.describe 'HasSearchIndexBackend', performs_jobs: true, searchindex: true,
       expect(result).not_to include({ name: 'updated_by_id', ref_name: 'updated_by' })
     end
 
-    it 'does exclude Ticket for bulk action updates' do
-      expect(organization).not_to be_search_index_indexable_bulk_updates(Ticket)
-    end
-
     it 'does include organization_id as relevant search index attribute' do
       expect(Ticket).to be_search_index_attribute_relevant('organization_id')
     end

+ 0 - 4
spec/models/user/has_search_index_backend_spec.rb

@@ -35,10 +35,6 @@ RSpec.describe 'HasSearchIndexBackend', searchindex: true, type: :model do
         expect(result).to eq([{ id: user.id.to_s, type: 'User' }])
       end
     end
-
-    it 'does include User for bulk action updates' do
-      expect(organization).to be_search_index_indexable_bulk_updates(User)
-    end
   end
 
   describe 'Updating group settings causes huge numbers of delayed jobs #4306' do