optimization

This commit is contained in:
Mojca Lorber 2016-09-05 10:58:37 +02:00
parent 6763d8e7a1
commit 740392c687
3 changed files with 13 additions and 21 deletions

View file

@ -6,12 +6,4 @@ module SearchHelper
end
experiments.uniq
end
def sub_results(el)
elements = []
el.each do |m|
elements << m
end
elements.uniq
end
end

View file

@ -150,12 +150,12 @@ class Protocol < ActiveRecord::Base
MyModule.joins(:protocols).where('protocols.parent_id = ?', id)
end
def linked_experiments
Experiment.where('id IN (?)', linked_modules.pluck(:experiment_id).uniq)
def linked_experiments(linked_mod)
Experiment.where('id IN (?)', linked_mod.pluck(:experiment_id).uniq)
end
def linked_projects
Project.where('id IN (?)', linked_experiments.pluck(:project_id).uniq)
def linked_projects(linked_exp)
Project.where('id IN (?)', linked_exp.pluck(:project_id).uniq)
end
def self.new_blank_for_module(my_module)

View file

@ -50,12 +50,12 @@
<br>
<% if protocol.nr_of_linked_children > 0 %>
<span>
<% if protocol.linked_modules %>
<% if protocol_linked_modules = protocol.linked_modules %>
<%=t "search.index.modules" %>
<% protocol.linked_modules.each_with_index do |mod, i| %>
<% protocol_linked_modules.each_with_index do |mod, i| %>
<%= render partial: "search/results/partials/my_module_text.html.erb",
locals: { my_module: mod } %>
<% if i != (sub_results(protocol.linked_modules).count - 1) %>
<% if i != (protocol_linked_modules.count - 1) %>
,&nbsp;
<% end %>
<% end %>
@ -63,12 +63,12 @@
</span>
<br>
<span>
<% if protocol.linked_experiments %>
<% if protocol_linked_experiments = protocol.linked_experiments(protocol_linked_modules) %>
<%=t "search.index.experiment" %>
<% protocol.linked_experiments.each_with_index do |exp, i| %>
<% protocol_linked_experiments.each_with_index do |exp, i| %>
<%= render partial: "search/results/partials/experiment_text.html.erb",
locals: { experiment: exp } %>
<% if i != (sub_results(protocol.linked_experiments).count - 1) %>
<% if i != (protocol_linked_experiments.count - 1) %>
,&nbsp;
<% end %>
<% end %>
@ -76,12 +76,12 @@
</span>
<br>
<span>
<% if protocol.linked_projects %>
<% if protocol_linked_projects = protocol.linked_projects(protocol_linked_experiments) %>
<%=t "search.index.project" %>
<% protocol.linked_projects.each_with_index do |pro, i| %>
<% protocol_linked_projects.each_with_index do |pro, i| %>
<%= render partial: "search/results/partials/project_text.html.erb",
locals: { project: pro } %>
<% if i != (sub_results(protocol.linked_projects).count - 1) %>
<% if i != (protocol_linked_projects.count - 1) %>
,&nbsp;
<% end %>
<% end %>