Fixes #15527 - api/v2/hosts is slow loading permissions
The .eager_load call when called with [] generates a SELECT query that selects all host attributes. This can cause it to take a lot longer when there are large number of hosts involved. These attributes are irrelevant in this context (when they are relevant, they're put in the scope_components hash)
With 5700 hosts, it takes about 50% less time to run this than to run it with eager_load.
Chaining the call with .where makes the call near-instant. It selects the host from the list of hosts we can see using the db directly.
Related issues
Bug #15527: api/v2/hosts is slow to load permissions for non-admins
Fixes #15527 - api/v2/hosts is slow loading permissions
The .eager_load call when called with [] generates a SELECT query that
selects all host attributes. This can cause it to take a lot longer
when there are large number of hosts involved. These attributes are
irrelevant in this context (when they are relevant, they're put in the
scope_components hash)
With 5700 hosts, it takes about 50% less time to run this than to run
it with eager_load.
Chaining the call with .where makes the call near-instant.
It selects the host from the list of hosts we can see using the db
directly.