When we generate fact values hash we always loaded a host for a given fact. This in combination with taxonomies queryies that are automatically generated caused roughly 6N+1 issue. We can preload all hosts that are required and use this in-memory cache for generating the hash.
Related issues
Bug #19742: API call for fact_values is slow when user is non-admin , Foreman 1.15.0
Fixes #19742 - cache hosts for fact values
When we generate fact values hash we always loaded a host for a given
fact. This in combination with taxonomies queryies that are
automatically generated caused roughly 6N+1 issue. We can preload all
hosts that are required and use this in-memory cache for generating the
hash.