Project

General

Profile

Refactor #8761

Improve performance of external search methods (of scoped_search)

Added by Šimon Lukašík over 3 years ago. Updated 24 days ago.

Status:
New
Priority:
Low
Category:
Database
Target version:
-
Difficulty:
Triaged:
No
Bugzilla link:
Pull request:
Team Backlog:
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

History

#1 Updated by Dominic Cleal over 3 years ago

  • Category set to Database

#2 Updated by Kavita Gaikwad about 1 year ago

  • Assignee set to Kavita Gaikwad
  • Target version set to 1.15.6

#3 Updated by Tomer Brisker 24 days ago

  • Target version deleted (1.15.6)

Also available in: Atom PDF