Refactor #8761

Improve performance of external search methods (of scoped_search)

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

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

Description

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    = hostgroups.map(&:subtree_ids).flatten.uniq
{ :conditions => "hostgroups.id 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: https://github.com/OpenSCAP/foreman_openscap/commit/a504cdf716b96fae8a6ab7353fca27bf23912852

History

#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