Project

General

Profile

Actions

Bug #39381

open

hosts index page loads full Host objects when only hostgroup_ids are needed

Added by Raman Vasikarla 18 days ago. Updated 18 days ago.

Status:
Ready For Testing
Priority:
Normal
Category:
-
Target version:
-
Difficulty:
Triaged:
No
Fixed in Releases:
Found in Releases:

Description

The `summarise_report_metrics` action in `HostsController` calls:

@hosts.map(&:hostgroup_id).compact.uniq

This loads all Host ActiveRecord objects already fetched for the page
into Ruby memory and extracts `hostgroup_id` in application code.

Using `pluck` instead:

@hosts.pluck(:hostgroup_id).compact.uniq

generates a `SELECT hostgroup_id FROM hosts WHERE ...` query that
returns only the needed column, avoiding unnecessary object allocation.
This is measurable on the hosts index page when displaying many hosts.

Actions #1

Updated by The Foreman Bot 18 days ago

  • Status changed from New to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/10951 added
Actions

Also available in: Atom PDF