|
@@ -58,10 +58,10 @@ module AgentHelper
|
|
|
end
|
|
|
end
|
|
|
|
|
|
- def agent_type_icon(agent)
|
|
|
- receiver_count = agent.links_as_receiver.length
|
|
|
- control_count = agent.control_links_as_controller.length
|
|
|
- source_count = agent.links_as_source.length
|
|
|
+ def agent_type_icon(agent, agents)
|
|
|
+ receiver_count = links_counter_cache(agents)[:links_as_receiver][agent.id] || 0
|
|
|
+ control_count = links_counter_cache(agents)[:control_links_as_controller][agent.id] || 0
|
|
|
+ source_count = links_counter_cache(agents)[:links_as_source][agent.id] || 0
|
|
|
|
|
|
if control_count > 0 && receiver_count > 0
|
|
|
content_tag('span') do
|
|
@@ -81,4 +81,22 @@ module AgentHelper
|
|
|
icon_tag('glyphicon-unchecked')
|
|
|
end
|
|
|
end
|
|
|
+
|
|
|
+ private
|
|
|
+
|
|
|
+ def links_counter_cache(agents)
|
|
|
+ @counter_cache ||= {}
|
|
|
+ @counter_cache[agents.__id__] ||= {}.tap do |cache|
|
|
|
+ agent_ids = agents.map(&:id)
|
|
|
+ cache[:links_as_receiver] = Hash[Link.where(receiver_id: agent_ids)
|
|
|
+ .group(:receiver_id)
|
|
|
+ .pluck('receiver_id', 'count(receiver_id) as id')]
|
|
|
+ cache[:links_as_source] = Hash[Link.where(source_id: agent_ids)
|
|
|
+ .group(:source_id)
|
|
|
+ .pluck('source_id', 'count(source_id) as id')]
|
|
|
+ cache[:control_links_as_controller] = Hash[ControlLink.where(controller_id: agent_ids)
|
|
|
+ .group(:controller_id)
|
|
|
+ .pluck('controller_id', 'count(controller_id) as id')]
|
|
|
+ end
|
|
|
+ end
|
|
|
end
|