Refactor #8761

Improve performance of external search methods (of scoped_search)

Added by Šimon Lukašík over 3 years ago. Updated 10 months ago.

Assigned To:Kavita Gaikwad
Target version:Team Anurag backlog
Difficulty: Bugzilla link:
Found in release: Pull request:
Story points-
Velocity based estimate-


Not sure, if the performance is the issue here, but the improvement can be made following way:

Currently, many of the :ext_method of scoped_search are defined like:

hostgroups      += Hostgroup.unscoped.with_taxonomy_scope.joins(:host_config_groups).where("host_config_groups.config_group_id IN (#{config_group_ids.join(',')})")
hostgroup_ids    =
{ :conditions => " IN(#{hostgroup_ids.join(',')})" }

That effectively leads to N+1 query. The found IDs needs to be parsed by Ruby to memory and back.

I have found a easy way to overcome this by defining the query using Arel and calling to_sql on it. Example:


#1 Updated by Dominic Cleal over 3 years ago

  • Category set to Database

#2 Updated by Kavita Gaikwad 10 months ago

  • Assigned To set to Kavita Gaikwad
  • Target version set to Team Anurag backlog

Also available in: Atom PDF