Fixes #38303 - the host count depends on the organization
If a user is in multiple organizations the host count which is displayed on different UI pages depends on the selected organization.
Ready for final review.
Essentially the issue is that if you go to that page as soon as you've added some hosts to a group, the counter will have the old value. Of course after 2 minutes and reloading the page it will be updated, but some might find this rather as a bug.
Then we can get rid of the cache. Its about displaying a host number - this shouldn't be mission critical :)
Any opinions on cache removal/rewrite instead of patching it for one issue and leaving the other?
We will need to dig deep into the history to understand why it's there i the first place. From the first look, it's a 7 years old issue: https://projects.theforeman.org/issues/24783. I wonder how to test the performance degradation if we are to remove the cache altogether.
I wonder how to test the performance degradation if we are to remove the cache altogether.
I don't think that someone would recognize any performance change if we drop the cache. I can run some speed tests next week.
Any opinions on cache removal/rewrite instead of patching it for one issue and leaving the other?
We will need to dig deep into the history to understand why it's there i the first place. From the first look, it's a 7 years old issue: https://projects.theforeman.org/issues/24783. I wonder how to test the performance degradation if we are to remove the cache altogether.
After weeks.... I'm sorry.
I have tested it. For 53 Hostgroups it takes with cache about 0.012829598 seconds and without 0.195574074 seconds So, I think it's worth to have this cache.
Actually, to get the host count for the host groups, it would run the same sql query 53 times:
SELECT "hosts".* FROM "hosts" WHERE "hosts"."type" = 'Host::Managed' AND "hosts"."organization_id" = 1 AND "hosts"."location_id" = 2 GROUP BY "hosts"."hostgroup_id
Afterwards, it selects the count of the hosts object per hostgroup_id. I think, this is pretty okish.
Now that I'm thinking out loud I'd say that my proposal also has it's drawbacks: key-values are being flooded into cache store without any removal :/
=> as described above, this is not the case. It would also be OK, to reduce the cache time from 2 minutes to 1 minute or even 30 seconds. If then, the count changes -> I think nobody would recognize it.
Any feedback on this change @ShimShtein ?
Looks good, let's merge it and see if we get some fallout. It definitely improves the original behavior