app/services/katello/applicability/applicable_content_helper.rb in katello-3.18.1.1 vs app/services/katello/applicability/applicable_content_helper.rb in katello-3.18.2
- old
+ new
@@ -58,21 +58,11 @@
return Katello::ModuleStream.find_by_sql([query, { content_facet_id: content_facet.id, repo_ids: self.bound_library_instance_repos }]).map(&:id)
end
def fetch_rpm_content_ids
- # Query for applicable RPM ids
- # -> Include all non-modular rpms or rpms that exist within installed module streams
- enabled_module_stream_ids = ::Katello::ModuleStream.
- joins("inner join katello_available_module_streams on
- katello_module_streams.name = katello_available_module_streams.name and
- katello_module_streams.stream = katello_available_module_streams.stream").
- joins("inner join katello_host_available_module_streams on
- katello_available_module_streams.id = katello_host_available_module_streams.available_module_stream_id").
- where("katello_host_available_module_streams.host_id = :content_facet_id and
- katello_host_available_module_streams.status = 'enabled'",
- :content_facet_id => self.content_facet.host.id).select(:id)
+ enabled_module_stream_ids = fetch_enabled_module_stream_ids
::Katello::Rpm.
joins("INNER JOIN katello_repository_rpms ON
katello_rpms.id = katello_repository_rpms.rpm_id").
joins("INNER JOIN katello_installed_packages ON
@@ -86,12 +76,40 @@
katello_installed_packages.id = katello_host_installed_packages.installed_package_id").
where("katello_repository_rpms.repository_id in (:bound_library_repos)",
:bound_library_repos => self.bound_library_instance_repos).
where("katello_host_installed_packages.host_id = :content_facet_id",
:content_facet_id => self.content_facet.host.id).
- where("katello_module_stream_rpms.module_stream_id is null or
- katello_module_stream_rpms.module_stream_id in (:enabled_module_streams)",
- :enabled_module_streams => enabled_module_stream_ids).pluck(:id).uniq
+ where("(katello_module_stream_rpms.module_stream_id IS NULL AND
+ katello_installed_packages.id NOT IN (:locked_modular_installed_packages)) OR
+ (katello_module_stream_rpms.module_stream_id IN (:enabled_module_streams)
+ AND katello_installed_packages.id IN (:locked_modular_installed_packages))",
+ :enabled_module_streams => enabled_module_stream_ids,
+ :locked_modular_installed_packages => locked_modular_installed_packages(enabled_module_stream_ids)).pluck(:id).uniq
+ end
+
+ def fetch_enabled_module_stream_ids
+ # Query for applicable RPM ids
+ # -> Include all non-modular rpms or rpms that exist within installed module streams
+ ::Katello::ModuleStream.
+ joins("inner join katello_available_module_streams on
+ katello_module_streams.name = katello_available_module_streams.name and
+ katello_module_streams.stream = katello_available_module_streams.stream").
+ joins("inner join katello_host_available_module_streams on
+ katello_available_module_streams.id = katello_host_available_module_streams.available_module_stream_id").
+ where("katello_host_available_module_streams.host_id = :content_facet_id and
+ katello_host_available_module_streams.status = 'enabled'",
+ :content_facet_id => self.content_facet.host.id).select(:id)
+ end
+
+ # Installed packages that are locked for the host due to enabled module stream membership
+ def locked_modular_installed_packages(enabled_module_streams)
+ rpms_in_enabled_module_streams = ::Katello::Rpm.
+ joins("INNER JOIN katello_module_stream_rpms ON katello_rpms.id = katello_module_stream_rpms.rpm_id").
+ where("katello_module_stream_rpms.module_stream_id IN (:enabled_module_streams)",
+ :enabled_module_streams => enabled_module_streams).select(:nvra, :epoch)
+
+ ::Katello::InstalledPackage.where(nvra: rpms_in_enabled_module_streams.map(&:nvra),
+ epoch: rpms_in_enabled_module_streams.map(&:epoch)).select(:id)
end
def newest_distinct_installed_packages_query
"SELECT DISTINCT ON (katello_installed_packages.name) katello_installed_packages.id " \
"FROM katello_installed_packages INNER JOIN " \