Follow up - ed8a152f28
- Fixes #2911 - Performance: Improved touching assets of users, organizations and tickets. Touching of Organization causes endless SearchIndexJob creation / Organization touch loop.
This commit is contained in:
parent
5bacbadf2f
commit
5b262c75b0
6 changed files with 55 additions and 10 deletions
|
@ -1,5 +1,6 @@
|
||||||
class ApplicationJob < ActiveJob::Base
|
class ApplicationJob < ActiveJob::Base
|
||||||
include ApplicationJob::HasDelayedJobMonitoringCompatibilty
|
include ApplicationJob::HasDelayedJobMonitoringCompatibilty
|
||||||
|
include ApplicationJob::HasQueuingPriority
|
||||||
|
|
||||||
# Automatically retry jobs that encountered a deadlock
|
# Automatically retry jobs that encountered a deadlock
|
||||||
# retry_on ActiveRecord::Deadlocked
|
# retry_on ActiveRecord::Deadlocked
|
||||||
|
|
15
app/jobs/application_job/has_queuing_priority.rb
Normal file
15
app/jobs/application_job/has_queuing_priority.rb
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
class ApplicationJob
|
||||||
|
module HasQueuingPriority
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
included do
|
||||||
|
queue_with_priority 200
|
||||||
|
end
|
||||||
|
|
||||||
|
class_methods do
|
||||||
|
def low_priority
|
||||||
|
queue_with_priority 300
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
7
app/jobs/search_index_associations_job.rb
Normal file
7
app/jobs/search_index_associations_job.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
class SearchIndexAssociationsJob < SearchIndexJob
|
||||||
|
|
||||||
|
def update_search_index(record)
|
||||||
|
record.search_index_update_associations_delta
|
||||||
|
record.search_index_update_associations_full
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,28 +1,29 @@
|
||||||
class SearchIndexJob < ApplicationJob
|
class SearchIndexJob < ApplicationJob
|
||||||
include HasActiveJobLock
|
include HasActiveJobLock
|
||||||
|
|
||||||
|
low_priority
|
||||||
|
|
||||||
retry_on StandardError, attempts: 20, wait: lambda { |executions|
|
retry_on StandardError, attempts: 20, wait: lambda { |executions|
|
||||||
executions * 10.seconds
|
executions * 10.seconds
|
||||||
}
|
}
|
||||||
|
|
||||||
def lock_key
|
def lock_key
|
||||||
# "SearchIndexJob/User/42/true"
|
# "SearchIndexJob/User/42"
|
||||||
"#{self.class.name}/#{arguments[0]}/#{arguments[1]}/#{arguments[2]}"
|
"#{self.class.name}/#{arguments[0]}/#{arguments[1]}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def perform(object, o_id, update_associations = true)
|
def perform(object, o_id)
|
||||||
@object = object
|
@object = object
|
||||||
@o_id = o_id
|
@o_id = o_id
|
||||||
|
|
||||||
record = @object.constantize.lookup(id: @o_id)
|
record = @object.constantize.lookup(id: @o_id)
|
||||||
return if !exists?(record)
|
return if !exists?(record)
|
||||||
|
|
||||||
|
update_search_index(record)
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_search_index(record)
|
||||||
record.search_index_update_backend
|
record.search_index_update_backend
|
||||||
|
|
||||||
return if !update_associations
|
|
||||||
|
|
||||||
record.search_index_update_associations_delta
|
|
||||||
record.search_index_update_associations_full
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -5,7 +5,7 @@ module HasSearchIndexBackend
|
||||||
included do
|
included do
|
||||||
after_create :search_index_update
|
after_create :search_index_update
|
||||||
after_update :search_index_update
|
after_update :search_index_update
|
||||||
after_touch :search_index_update
|
after_touch :search_index_update_touch
|
||||||
after_destroy :search_index_destroy
|
after_destroy :search_index_destroy
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -24,6 +24,26 @@ update search index, if configured - will be executed automatically
|
||||||
# start background job to transfer data to search index
|
# start background job to transfer data to search index
|
||||||
return true if !SearchIndexBackend.enabled?
|
return true if !SearchIndexBackend.enabled?
|
||||||
|
|
||||||
|
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)
|
SearchIndexJob.perform_later(self.class.to_s, id)
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
@ -49,7 +69,7 @@ returns
|
||||||
# we can not use the delta function for this because of the excluded
|
# we can not use the delta function for this because of the excluded
|
||||||
# ticket article attachments. see explain in delta function
|
# ticket article attachments. see explain in delta function
|
||||||
Ticket.select('id').where(organization_id: id).order(id: :desc).limit(10_000).pluck(:id).each do |ticket_id|
|
Ticket.select('id').where(organization_id: id).order(id: :desc).limit(10_000).pluck(:id).each do |ticket_id|
|
||||||
SearchIndexJob.perform_later('Ticket', ticket_id, false)
|
SearchIndexJob.perform_later('Ticket', ticket_id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -312,6 +312,7 @@ class ReportTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
# execute background jobs
|
# execute background jobs
|
||||||
Scheduler.worker(true)
|
Scheduler.worker(true)
|
||||||
|
SearchIndexBackend.refresh
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'compare' do
|
test 'compare' do
|
||||||
|
|
Loading…
Reference in a new issue