Project

General

Profile

Actions

Refactor #8761

open

Improve performance of external search methods (of scoped_search)

Added by Šimon Lukašík over 9 years ago. Updated over 5 years ago.

Status:
New
Priority:
Low
Category:
Database
Target version:
-
Difficulty:
Triaged:
No
Fixed in Releases:
Found in Releases:

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

Actions #1

Updated by Dominic Cleal about 9 years ago

  • Category set to Database
Actions #2

Updated by Kavita Gaikwad over 6 years ago

  • Assignee set to Kavita Gaikwad
  • Target version set to 1.15.6
Actions #3

Updated by Tomer Brisker over 5 years ago

  • Target version deleted (1.15.6)
Actions

Also available in: Atom PDF