diff --git a/BrainPortal/app/controllers/portal_controller.rb b/BrainPortal/app/controllers/portal_controller.rb
index 526837ddf..e02b0b1a3 100644
--- a/BrainPortal/app/controllers/portal_controller.rb
+++ b/BrainPortal/app/controllers/portal_controller.rb
@@ -46,19 +46,14 @@ def welcome #:nodoc:
@default_data_provider = DataProvider.find_by_id(current_user.meta["pref_data_provider_id"])
@default_bourreau = Bourreau.find_by_id(current_user.meta["pref_bourreau_id"])
- @tools = Tool
- .all
- .order(:name)
- .to_a
- .reject { |t| t.category == 'background' }
- .select { |t| t.tool_configs.to_a.any? { |tc|
- tc.bourreau_id.present? &&
- tc.bourreau_id > 0 &&
- tc.version_name.present?
- }
- }
-
- @avaiable_tools = @tools
+ @tool_count = Tool
+ .joins(:tool_configs)
+ .where.not(category: 'background')
+ .where('tool_configs.bourreau_id IS NOT NULL')
+ .where('tool_configs.bourreau_id > 0')
+ .where('tool_configs.version_name IS NOT NULL')
+ .distinct
+ .count
@dashboard_messages = Message
.where(:message_type => 'cbrain_dashboard')
diff --git a/BrainPortal/app/views/portal/welcome.html.erb b/BrainPortal/app/views/portal/welcome.html.erb
index b7e545898..0df2ac6a6 100644
--- a/BrainPortal/app/views/portal/welcome.html.erb
+++ b/BrainPortal/app/views/portal/welcome.html.erb
@@ -167,7 +167,7 @@
Your current time: <%= to_localtime(Time.now, :datetime) %>
- Tools available to you ( out of <%= link_to @tools.count , available_path %> ) :
+ Tools available to you ( out of <%= link_to @tool_count , available_path %> ) :
<%= array_to_table(current_user.available_tools.where( "category <> 'background'" ).to_a.map(&:name).sort, :table_class => 'simple', :cols => 4) %>