Skip to content

Commit

Permalink
Merge pull request #6634 from coolo/optimtize_flags_rendering
Browse files Browse the repository at this point in the history
Just fetch the flags and check if they are empty afterwards
  • Loading branch information
vpereira committed Dec 17, 2018
2 parents 1e9d3d3 + 6938524 commit b9f073f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
12 changes: 12 additions & 0 deletions src/api/app/helpers/flag_helper.rb
Expand Up @@ -164,4 +164,16 @@ def self.xml_disabled_for?(xmlhash, flagtype)
end
disabled
end

def self.render(my_model, xml)
flags_sorted = my_model.flags.includes(:architecture).group_by(&:flag)

# the defined order is by type
FlagHelper.flag_types.each do |flag_name|
next unless flags_sorted.key?(flag_name)
xml.send(flag_name) do
flags_sorted[flag_name].each { |flag| flag.to_xml(xml) }
end
end
end
end
10 changes: 1 addition & 9 deletions src/api/app/views/models/_package.xml.builder
Expand Up @@ -9,15 +9,7 @@ xml.package(name: my_model.name, project: my_model.project.name) do

my_model.render_relationships(xml)

FlagHelper.flag_types.each do |flag_name|
flaglist = my_model.flags.of_type(flag_name)
next if flaglist.empty?
xml.send(flag_name) do
flaglist.each do |flag|
flag.to_xml(xml)
end
end
end
FlagHelper.render(my_model, xml)

xml.url(my_model.url) if my_model.url.present?
xml.bcntsynctag(my_model.bcntsynctag) if my_model.bcntsynctag.present?
Expand Down
10 changes: 1 addition & 9 deletions src/api/app/views/models/_project.xml.builder
Expand Up @@ -20,15 +20,7 @@ xml.project(project_attributes) do
my_model.render_relationships(xml)

repos = my_model.repositories.not_remote.sort { |a, b| b.name <=> a.name }
FlagHelper.flag_types.each do |flag_name|
flaglist = my_model.flags.of_type(flag_name)
next if flaglist.empty?
xml.send(flag_name) do
flaglist.each do |flag|
flag.to_xml(xml)
end
end
end
FlagHelper.render(my_model, xml)

repos.each do |repo|
params = {}
Expand Down

0 comments on commit b9f073f

Please sign in to comment.