Merge pull request #1804 from dsander/cache-agent-type-dropdown

Cache Agent type select options in Agent#new
This commit is contained in:
Dominik Sander 2016-11-22 21:04:29 +01:00 committed by GitHub
commit 5d69bd2d93
3 changed files with 8 additions and 2 deletions

View file

@ -82,6 +82,12 @@ module AgentHelper
end
end
def agent_type_select_options
Rails.cache.fetch('agent_type_select_options') do
[['Select an Agent Type', 'Agent', {title: ''}]] + Agent.types.map {|type| [agent_type_to_human(type.name), type, {title: h(Agent.build_for_type(type.name, User.new(id: 0), {}).html_description.lines.first.strip)}] }
end
end
private
def links_counter_cache(agents)

View file

@ -25,7 +25,7 @@
<% if @agent.new_record? %>
<div class="form-group type-select">
<%= f.label :type %>
<%= f.select :type, options_for_select([['Select an Agent Type', 'Agent', {title: ''}]] + Agent.types.map {|type| [agent_type_to_human(type.name), type, {title: h(Agent.build_for_type(type.name,current_user,{}).html_description.lines.first.strip)}] }, @agent.type), {}, class: 'form-control', autofocus: true %>
<%= f.select :type, options_for_select(agent_type_select_options, @agent.type), {}, class: 'form-control', autofocus: true %>
</div>
<% end %>
</div>

View file

@ -59,7 +59,7 @@ Huginn::Application.configure do
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
# Use a different cache store in production
# config.cache_store = :mem_cache_store
config.cache_store = :memory_store
# Enable serving of images, stylesheets, and JavaScripts from an asset server
if ENV['ASSET_HOST'].present?