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.
This commit is contained in:
parent
0344ad14c1
commit
088c11a12c
|
@ -213,7 +213,8 @@ class TopicLink < ActiveRecord::Base
|
||||||
unless TopicLink.exists?(topic_id: post.topic_id, post_id: post.id, url: url)
|
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?
|
file_extension = File.extname(parsed.path)[1..10].downcase unless parsed.path.nil? || File.extname(parsed.path).empty?
|
||||||
begin
|
begin
|
||||||
TopicLink.create!(post_id: post.id,
|
TopicLink.create(
|
||||||
|
post_id: post.id,
|
||||||
user_id: post.user_id,
|
user_id: post.user_id,
|
||||||
topic_id: post.topic_id,
|
topic_id: post.topic_id,
|
||||||
url: url,
|
url: url,
|
||||||
|
@ -222,7 +223,8 @@ class TopicLink < ActiveRecord::Base
|
||||||
link_topic_id: topic&.id,
|
link_topic_id: topic&.id,
|
||||||
link_post_id: reflected_post.try(:id),
|
link_post_id: reflected_post.try(:id),
|
||||||
quote: link.is_quote,
|
quote: link.is_quote,
|
||||||
extension: file_extension)
|
extension: file_extension
|
||||||
|
)
|
||||||
rescue ActiveRecord::RecordNotUnique
|
rescue ActiveRecord::RecordNotUnique
|
||||||
# it's fine
|
# it's fine
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue