Fixed issue #2108 - 30 concurrent agents + each of them 30 overviews - script/scheduler.rb takes 100% CPU time - background jobs cannot be processed.
This commit is contained in:
parent
fb0ef19e7d
commit
ce5f5a035e
6 changed files with 30 additions and 7 deletions
|
@ -115,10 +115,13 @@ returns
|
|||
group_agent_roles_ids = Role.joins(', roles_groups').where("roles.id = roles_groups.role_id AND roles_groups.access = 'full' AND roles_groups.group_id = ? AND roles.id IN (?)", group.id, agent_role_ids).pluck(:id)
|
||||
group_agent_role_user_ids = User.joins(:roles).where(roles: { id: group_agent_roles_ids }).pluck(:id)
|
||||
|
||||
User.where(id: group_agent_user_ids.concat(group_agent_role_user_ids).uniq, active: true).each do |user|
|
||||
dependencies[:group_id][group.id][:owner_id].push user.id
|
||||
next if agents[user.id]
|
||||
agents[user.id] = true
|
||||
User.where(id: group_agent_user_ids.concat(group_agent_role_user_ids).uniq, active: true).pluck(:id).each do |user_id|
|
||||
dependencies[:group_id][group.id][:owner_id].push user_id
|
||||
next if agents[user_id]
|
||||
agents[user_id] = true
|
||||
next if assets[:User] && assets[:User][user_id]
|
||||
user = User.lookup(id: user_id)
|
||||
next if !user
|
||||
assets = user.assets(assets)
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
class Sessions::Backend::Base
|
||||
|
||||
attr_writer :user
|
||||
attr_writer :time_now
|
||||
|
||||
def initialize(user, asset_lookup, client, client_id, ttl = 10)
|
||||
@user = user
|
||||
|
@ -9,6 +10,7 @@ class Sessions::Backend::Base
|
|||
@ttl = ttl
|
||||
@asset_lookup = asset_lookup
|
||||
@last_change = nil
|
||||
@time_now = Time.zone.now.to_i
|
||||
end
|
||||
|
||||
def asset_push(record, assets)
|
||||
|
@ -16,7 +18,7 @@ class Sessions::Backend::Base
|
|||
@asset_lookup[class_name] ||= {}
|
||||
@asset_lookup[class_name][record.id] = {
|
||||
updated_at: record.updated_at,
|
||||
pushed_at: Time.zone.now,
|
||||
pushed_at: @time_now,
|
||||
}
|
||||
record.assets(assets)
|
||||
end
|
||||
|
@ -32,7 +34,7 @@ class Sessions::Backend::Base
|
|||
return true if @asset_lookup[class_name][record_id].blank?
|
||||
return true if @asset_lookup[class_name][record_id][:updated_at] < updated_at
|
||||
return true if @asset_lookup[class_name][record_id][:pushed_at].blank?
|
||||
return true if @asset_lookup[class_name][record_id][:pushed_at] < Time.zone.now - 2.hours
|
||||
return true if @asset_lookup[class_name][record_id][:pushed_at] < @time_now - 7200
|
||||
false
|
||||
end
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ class Sessions::Backend::Collections < Sessions::Backend::Base
|
|||
@ttl = ttl
|
||||
@asset_lookup = asset_lookup
|
||||
@backends = backend
|
||||
@time_now = Time.zone.now.to_i
|
||||
end
|
||||
|
||||
def push
|
||||
|
|
|
@ -2,6 +2,7 @@ class Sessions::Backend::Collections::Base < Sessions::Backend::Base
|
|||
class << self; attr_accessor :model, :permissions end
|
||||
|
||||
attr_writer :user
|
||||
attr_writer :time_now
|
||||
|
||||
def initialize(user, asset_lookup, client, client_id, ttl)
|
||||
@user = user
|
||||
|
@ -10,6 +11,7 @@ class Sessions::Backend::Collections::Base < Sessions::Backend::Base
|
|||
@ttl = ttl
|
||||
@asset_lookup = asset_lookup
|
||||
@last_change = nil
|
||||
@time_now = Time.zone.now.to_i
|
||||
end
|
||||
|
||||
def load
|
||||
|
@ -53,6 +55,7 @@ class Sessions::Backend::Collections::Base < Sessions::Backend::Base
|
|||
end
|
||||
|
||||
# collect assets
|
||||
@time_now = Time.zone.now.to_i
|
||||
assets = {}
|
||||
items.each do |item|
|
||||
next if !asset_needed?(item)
|
||||
|
|
|
@ -15,6 +15,7 @@ class Sessions::Backend::TicketOverviewList < Sessions::Backend::Base
|
|||
@last_overview = {}
|
||||
@last_overview_change = nil
|
||||
@last_ticket_change = nil
|
||||
@time_now = Time.zone.now.to_i
|
||||
end
|
||||
|
||||
def load
|
||||
|
@ -87,6 +88,8 @@ class Sessions::Backend::TicketOverviewList < Sessions::Backend::Base
|
|||
)
|
||||
end
|
||||
|
||||
@time_now = Time.zone.now.to_i
|
||||
|
||||
# push overviews
|
||||
results = []
|
||||
index_and_lists.each do |data|
|
||||
|
@ -114,7 +117,6 @@ class Sessions::Backend::TicketOverviewList < Sessions::Backend::Base
|
|||
}
|
||||
results.push result
|
||||
else
|
||||
|
||||
@client.log "push overview_list #{overview.link} for user #{@user.id}"
|
||||
|
||||
# send update to browser
|
||||
|
|
|
@ -55,20 +55,29 @@ class SessionBasicTicketTest < ActiveSupport::TestCase
|
|||
|
||||
travel 120.minutes
|
||||
|
||||
client1.time_now = Time.zone.now.to_i
|
||||
assert(client1.asset_needed_by_updated_at?(ticket.class.to_s, ticket.id, ticket.updated_at))
|
||||
client1.asset_push(ticket, {})
|
||||
|
||||
client2.time_now = Time.zone.now.to_i
|
||||
assert(client2.asset_needed_by_updated_at?(ticket.class.to_s, ticket.id, ticket.updated_at))
|
||||
client2.asset_push(ticket, {})
|
||||
|
||||
client1.time_now = Time.zone.now.to_i
|
||||
assert_not(client1.asset_needed_by_updated_at?(ticket.class.to_s, ticket.id, ticket.updated_at))
|
||||
client1.asset_push(ticket, {})
|
||||
|
||||
client2.time_now = Time.zone.now.to_i
|
||||
assert_not(client2.asset_needed_by_updated_at?(ticket.class.to_s, ticket.id, ticket.updated_at))
|
||||
client2.asset_push(ticket, {})
|
||||
|
||||
ticket.touch
|
||||
|
||||
client1.time_now = Time.zone.now.to_i
|
||||
assert(client1.asset_needed_by_updated_at?(ticket.class.to_s, ticket.id, ticket.updated_at))
|
||||
client1.asset_push(ticket, {})
|
||||
|
||||
client2.time_now = Time.zone.now.to_i
|
||||
assert(client2.asset_needed_by_updated_at?(ticket.class.to_s, ticket.id, ticket.updated_at))
|
||||
client2.asset_push(ticket, {})
|
||||
|
||||
|
@ -77,8 +86,11 @@ class SessionBasicTicketTest < ActiveSupport::TestCase
|
|||
|
||||
travel 125.minutes
|
||||
|
||||
client1.time_now = Time.zone.now.to_i
|
||||
assert(client1.asset_needed?(ticket))
|
||||
client1.asset_push(ticket, {})
|
||||
|
||||
client2.time_now = Time.zone.now.to_i
|
||||
assert(client2.asset_needed?(ticket))
|
||||
client2.asset_push(ticket, {})
|
||||
|
||||
|
|
Loading…
Reference in a new issue