mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 07:11:34 +08:00
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:
@ -213,16 +213,18 @@ 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(
|
||||||
user_id: post.user_id,
|
post_id: post.id,
|
||||||
topic_id: post.topic_id,
|
user_id: post.user_id,
|
||||||
url: url,
|
topic_id: post.topic_id,
|
||||||
domain: parsed.host || Discourse.current_hostname,
|
url: url,
|
||||||
internal: internal,
|
domain: parsed.host || Discourse.current_hostname,
|
||||||
link_topic_id: topic&.id,
|
internal: internal,
|
||||||
link_post_id: reflected_post.try(:id),
|
link_topic_id: topic&.id,
|
||||||
quote: link.is_quote,
|
link_post_id: reflected_post.try(:id),
|
||||||
extension: file_extension)
|
quote: link.is_quote,
|
||||||
|
extension: file_extension
|
||||||
|
)
|
||||||
rescue ActiveRecord::RecordNotUnique
|
rescue ActiveRecord::RecordNotUnique
|
||||||
# it's fine
|
# it's fine
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user