Description of problem: The calculation of errata applicability takes long time to complete. It will take 5 to 10 minutes to calculate if the host has thousands of installed modular packages. How reproducible: Easy Steps to Reproduce: 1. Prepare a RHEL 8 client and register it to the Satellite. 2. Enable the appstream repository. 3. Enable and install as many module streams as possible. 4. After that force upload the package profile to the Satellite to trigger the "Katello::Applicability::Hosts::BulkGenerate" task. Actual results: ~~~ Label: Actions::Katello::Applicability::Hosts::BulkGenerate Status: stopped Result: success ... 2: Actions::Katello::Applicability::Hosts::BulkGenerate (success) [ 193.02s / 193.02s ] Queue: hosts_queue Started at: 2023-07-05 00:14:14 UTC Ended at: 2023-07-05 00:17:27 UTC Real time: 193.02s Execution time (excluding suspended state): 193.02s ~~~ Expected results: should at least take second to complete. Additional info: We can use the following rake script to test the peformance. ~~~ cat << EOF | foreman-rake console cf = Host.find(XXXX).content_facet bound_repos = cf.bound_repositories.collect {|repo| repo.library_instance_id.nil? ? repo.id : repo.library_instance_id} helper = Katello::Applicability::ApplicableContentHelper.new(cf, ::Katello::Rpm, bound_repos) helper.fetch_enabled_module_stream_ids.size Benchmark.measure {p helper.locked_modular_installed_packages(helper.fetch_enabled_module_stream_ids).size} EOF ~~~ Example output of the rake ~~~ ... helper.fetch_enabled_module_stream_ids.size 442 Benchmark.measure {p helper.locked_modular_installed_packages(helper.fetch_enabled_module_stream_ids).size} 3021 #<Benchmark::Tms:0x0000000014c0e4a0 @label="", @real=114.56473832399934, @cstime=0.0, @cutime=0.0, @stime=0.017389999999998906, @utime=1.518035999999995, @total=1.535425999999994> ~~~