From 4b73412254b89b638e1bb1966cf77bbbb50fcb50 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 | 16 +++++++++++++--- 1 file changed, 13 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..d593df76c81 100644 --- a/app/models/katello/concerns/host_managed_extensions.rb +++ b/app/models/katello/concerns/host_managed_extensions.rb @@ -348,11 +348,21 @@ 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. + registered_time = subscription_facet&.registered_at + use_create_or_find_by = registered_time.nil? || registered_time > 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)