FIX: Don't raise an exception if a TopicLink cannot be created

FIX: Don’t raise an exception if a TopicLink cannot be created

This can happen under concurrency and it’s fine. If a TopicLink already exists we can continue on without raising an error.

diff --git a/app/models/topic_link.rb b/app/models/topic_link.rb
index f913dc6..afc6fae 100644
--- a/app/models/topic_link.rb
+++ b/app/models/topic_link.rb
@@ -213,16 +213,18 @@ class TopicLink < ActiveRecord::Base
     unless TopicLink.exists?(topic_id: post.topic_id, post_id: post.id, url: url)
       file_extension = File.extname(parsed.path)[1..10].downcase unless parsed.path.nil? || File.extname(parsed.path).empty?
       begin
-        TopicLink.create!(post_id: post.id,
-                          user_id: post.user_id,
-                          topic_id: post.topic_id,
-                          url: url,
-                          domain: parsed.host || Discourse.current_hostname,
-                          internal: internal,
-                          link_topic_id: topic&.id,
-                          link_post_id: reflected_post.try(:id),
-                          quote: link.is_quote,
-                          extension: file_extension)
+        TopicLink.create(
+          post_id: post.id,
+          user_id: post.user_id,
+          topic_id: post.topic_id,
+          url: url,
+          domain: parsed.host || Discourse.current_hostname,
+          internal: internal,
+          link_topic_id: topic&.id,
+          link_post_id: reflected_post.try(:id),
+          quote: link.is_quote,
+          extension: file_extension
+        )
       rescue ActiveRecord::RecordNotUnique
         # it's fine
       end

GitHub sha: 088c11a1

not a huge fan of too many comments in the code base, but @tgxworld likes going around and adding create! in this case a comment is probably useful to stop people from swapping it back to create!

Oh my … what a rabbit hole…

In my defense this issue has plagued us for many many years and we kept on adding more and more protections.

This should avoid issues going forward without hitting so many concurrency issues on one of our biggest tables.