Unfortunately I think the issue is caused by the large number of host groups.
As described here in a similar issue: Creating a new host takes 10–15 minutes in certain hostgroups, Foreman can become very slow when there are many hostgroups or deeply nested hierarchies, since each one adds more database queries and parameter inheritance lookups.
I see you also commented on a similar case here: Foreman 1.24.2 – very slow hostgroup view and edit for non-admin user.
So this looks like the same underlying limitation - the number and complexity of hostgroups. Reducing or flattening the hostgroup structure, or filtering them in the UI, should help improve performance.