From e69483babf4dd0997589fadf526157c1786ecd01 Mon Sep 17 00:00:00 2001 From: Jeremy Lenz Date: Thu, 1 Feb 2024 17:04:17 -0500 Subject: [PATCH] Fixes #37137 - Revert to old method of creating module streams after registration --- .../katello/concerns/host_managed_extensions.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/models/katello/concerns/host_managed_extensions.rb b/app/models/katello/concerns/host_managed_extensions.rb index 1bc376e9837..68d044cdec4 100644 --- a/app/models/katello/concerns/host_managed_extensions.rb +++ b/app/models/katello/concerns/host_managed_extensions.rb @@ -348,11 +348,20 @@ def import_enabled_repositories(repos) end def import_module_streams(module_streams) + # create_or_find_by avoids race conditions during concurrent registrations but clogs postgres logs with harmless errors. + # So we'll use create_or_find_by! during registration and first_or_create! otherwise. + use_create_or_find_by = subscription_facet&.registered_at.nil? || subscription_facet&.registered_at > 1.minute.ago streams = {} module_streams.each do |module_stream| - stream = AvailableModuleStream.create_or_find_by!(name: module_stream["name"], - context: module_stream["context"], - stream: module_stream["stream"]) + if use_create_or_find_by + stream = AvailableModuleStream.create_or_find_by!(name: module_stream["name"], + context: module_stream["context"], + stream: module_stream["stream"]) + else + stream = AvailableModuleStream.where(name: module_stream["name"], + context: module_stream["context"], + stream: module_stream["stream"]).first_or_create! + end streams[stream.id] = module_stream end sync_available_module_stream_associations(streams)