Project

General

Profile

Bug #14050

N+1 query on hosts#index from host's build token

Added by Dominic Cleal about 3 years ago. Updated 11 months ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Database
Target version:
Difficulty:
Triaged:
Bugzilla link:
Team Backlog:
Fixed in Releases:
Found in Releases:

Description

When accessing the hosts#index since #5883, the UI's performing a N+1 database lookup to find the tokens to calculate the build status.

 | http://0.0.0.0:3000/hosts
 | N+1 Query detected
 |   Host::Managed => [:token]
 |   Add to your finder: :includes => [:token]
 | N+1 Query method call stack
 |   /home/dcleal/code/foreman/foreman/app/models/host/managed.rb:266:in `token_expired?'
 |   /home/dcleal/code/foreman/foreman/app/models/host_status/build_status.rb:54:in `token_expired?'
 |   /home/dcleal/code/foreman/foreman/app/models/host_status/build_status.rb:35:in `to_status'
 |   /home/dcleal/code/foreman/foreman/app/models/host_status/build_status.rb:25:in `to_global'
 |   /home/dcleal/code/foreman/foreman/app/models/host_status/global.rb:19:in `block in build'
 |   /home/dcleal/code/foreman/foreman/app/models/host_status/global.rb:19:in `map'
 |   /home/dcleal/code/foreman/foreman/app/models/host_status/global.rb:19:in `build'
 |   /home/dcleal/code/foreman/foreman/app/models/host/managed.rb:878:in `build_global_status'
 |   /home/dcleal/code/foreman/foreman/app/helpers/hosts_helper.rb:109:in `host_global_status_icon_class_for_host'
 |   /home/dcleal/code/foreman/foreman/app/helpers/hosts_helper.rb:98:in `name_column'
 |   /home/dcleal/code/foreman/foreman/app/views/hosts/_list.html.erb:22:in `block in _app_views_hosts__list_html_erb__717094616139966240_70130187070520'
 |   /home/dcleal/code/foreman/foreman/app/views/hosts/_list.html.erb:17:in `_app_views_hosts__list_html_erb__717094616139966240_70130187070520'
 |   /home/dcleal/code/foreman/foreman/app/views/hosts/index.html.erb:4:in `_app_views_hosts_index_html_erb__4161764017543335258_99759220'

The tokens need to be preloaded in the same way that the last report is in #10782, #13112.


Related issues

Related to Foreman - Bug #5883: Host: provide user indication that the build token has expiredClosed2014-05-22

Associated revisions

Revision 9738552e (diff)
Added by Tom Caspy about 3 years ago

fixes #14050 - resolving N+1 query on hosts#index

History

#1 Updated by Dominic Cleal about 3 years ago

  • Related to Bug #5883: Host: provide user indication that the build token has expired added

#2 Updated by The Foreman Bot about 3 years ago

  • Status changed from New to Ready For Testing
  • Assignee set to Tom Caspy
  • Pull request https://github.com/theforeman/foreman/pull/3340 added

#3 Updated by Tom Caspy about 3 years ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100

Also available in: Atom PDF