Foreman 1.10.2-1.el7 Organizations and Locations Slowness

Howdy there,

After enabling Organizations and Locations in Foreman 1.10.2 and playing
with it, our team noticed that Ruby would spin for a very long time to
generate the Organization or Location edit pages, to an order where in a
lot of cases it would simply time out.
Reviewing the codebase, It looks like part of why is that it will pull in
taxonomies to compare regardless within app/models/provisioning_template.rb
so I made a quick patch to avoid needless lookups when a template can be
found.

There doesn't appear to be any negative effect of this change, however this
is my first time dealing with Ruby and I've not used this Foreman feature
extensively enough to be sure.

provisioning_template.rb MD5: 95f9a84cfcc8ed417ab7b94ce7f06d73

Diff:
85c85
< if !defined? templates and opts[:hostgroup_id] and
opts[:environment_id]

··· --- > if opts[:hostgroup_id] and opts[:environment_id] 92c92 < if !defined? templates and opts[:hostgroup_id] --- > if opts[:hostgroup_id] 99c99 < if !defined? templates and opts[:environment_id] --- > if opts[:environment_id] 107,111c107 < if !defined? templates < template ||= templates.joins(:os_default_templates).where("os_default_templates.operatingsystem_id" => opts[:operatingsystem_id]).first < end < < # return template or nil --- > template ||= templates.joins(:os_default_templates).where("os_default_templates.operatingsystem_id" => opts[:operatingsystem_id]).first

I was seeing a 30 second load time with only 3 hosts ( testing with a small
number due to issues ) and with this change it’s down to 3 seconds to load.

Let me know if there’s any insight or commentary, I’d love to better
understand.

Hello,

could you please open a PR on github? We could better discuss changes there.
If you're not sure how to do it, please read howto at
http://theforeman.org/contribute.html#Code-relatedcontributions

··· -- Marek

On Monday 07 of March 2016 16:05:44 James Vess wrote:

Howdy there,

After enabling Organizations and Locations in Foreman 1.10.2 and playing
with it, our team noticed that Ruby would spin for a very long time to
generate the Organization or Location edit pages, to an order where in a
lot of cases it would simply time out.
Reviewing the codebase, It looks like part of why is that it will pull in
taxonomies to compare regardless within app/models/provisioning_template.rb
so I made a quick patch to avoid needless lookups when a template can be
found.

There doesn’t appear to be any negative effect of this change, however this
is my first time dealing with Ruby and I’ve not used this Foreman feature
extensively enough to be sure.

provisioning_template.rb MD5: 95f9a84cfcc8ed417ab7b94ce7f06d73

Diff:
85c85
< if !defined? templates and opts[:hostgroup_id] and
opts[:environment_id]

if opts[:hostgroup_id] and opts[:environment_id]

92c92
< if !defined? templates and opts[:hostgroup_id]

if opts[:hostgroup_id]

99c99
< if !defined? templates and opts[:environment_id]

if opts[:environment_id]

107,111c107
< if !defined? templates
< template ||=
templates.joins(:os_default_templates).where(“os_default_templates.operating
system_id” => opts[:operatingsystem_id]).first
< end
<
< # return template or nil

template ||=

templates.joins(:os_default_templates).where(“os_default_templates.operating
system_id” => opts[:operatingsystem_id]).first

I was seeing a 30 second load time with only 3 hosts ( testing with a small
number due to issues ) and with this change it’s down to 3 seconds to load.

Let me know if there’s any insight or commentary, I’d love to better
understand.