Bug #31024

Host show api endpoint is slow for non-admin user

Added by Ondřej Ezr about 2 years ago. Updated about 2 years ago.

Target version:
Bugzilla link:
Fixed in Releases:
Found in Releases:
Red Hat JIRA:


Cloned from

Description of problem:
When a non-admin user fetches host details, it takes much more time than for admin user. Something similar like:

but just for getting host info, not editing.

When applied upstream patch from bz1598855 to Sat 6.4.1, no improvement in performance was noticed. So it is a separate issue (or not sufficiently general patch covering both scenarios).

Version-Release number of selected component (if applicable):
6.4.1, seen also on 6.3

How reproducible:

Steps to Reproduce:
1. Have a Satellite with some Hosts (I think the count does not matter)
2. Have a non-admin user with all rights but not Admin checkbox.
3. Run:

time curl -X GET -s -k -u nonadmin:password https://$(hostname -f)/api/v2/hosts/529 > /dev/null

4. Select Admin checkbox for the user.
5. Run the curl command again.

Actual results:
3. shows several times higher time than 5.

Expected results:
3. shows comparable time like 5. Some higher value is understandable, but not several times more.

Additional info:

Associated revisions

Revision 1d0e18a1 (diff)
Added by Tomer Brisker about 2 years ago

Fixes #31024 - Optimize host taxonomy_conditions (#8101)

Previously, `Taxonomy.expend` was used to get the taxonomies for the
user or the current taxonomy, then all taxonomies were iterated over
to get the subtree ids.
However, when `Taxonomy.current` is `nil`, we already get
all subtree ids since `expend` calls `my_taxonomy` which return the
subtrees already. Instead, we can directly call the
`taxonomy_and_subtree_id` method to get the ids. In the case of admin
user, we don't need a taxonomy condition for `nil` taxonomies as that
should return all taxonomies.
When `Taxonomy.current` is present, we can call the `subtree_ids` method
on it directly without needing to wrap it in an array and iterate over
In the case of `nil` current taxonomies, this can potentially save
hundreds of useless database queries to check subtree ids for all the
taxonomies a user has access to. For example, in my setup every call to
`/api/hosts/$id` triggered 20 queries per taxonomy the user is assigned
to (due to the permission section of the `show.json.rabl` view).


#1 Updated by The Foreman Bot about 2 years ago

  • Assignee set to Tomer Brisker
  • Status changed from New to Ready For Testing
  • Pull request added

#2 Updated by Tomer Brisker about 2 years ago

  • Subject changed from Host detail page load is slow for non-admin user to Host show api endpoint is slow for non-admin user

#3 Updated by The Foreman Bot about 2 years ago

  • Fixed in Releases 2.3.0 added

#4 Updated by Tomer Brisker about 2 years ago

  • Status changed from Ready For Testing to Closed

Also available in: Atom PDF