mirror of
https://github.com/discourse/discourse.git
synced 2025-03-22 16:05:33 +08:00
FIX: don't raise exception when a quote was already extracted
This commit is contained in:
parent
3cc6fabb62
commit
dec8a861f0
@ -20,22 +20,22 @@ class QuotedPost < ActiveRecord::Base
|
|||||||
next if uniq[[topic_id,post_number]]
|
next if uniq[[topic_id,post_number]]
|
||||||
uniq[[topic_id,post_number]] = true
|
uniq[[topic_id,post_number]] = true
|
||||||
|
|
||||||
|
begin
|
||||||
|
# It would be so much nicer if we used post_id in quotes
|
||||||
|
results = exec_sql "INSERT INTO quoted_posts(post_id, quoted_post_id, created_at, updated_at)
|
||||||
|
SELECT :post_id, p.id, current_timestamp, current_timestamp
|
||||||
|
FROM posts p
|
||||||
|
LEFT JOIN quoted_posts q on q.post_id = :post_id AND q.quoted_post_id = p.id
|
||||||
|
WHERE post_number = :post_number AND
|
||||||
|
topic_id = :topic_id AND
|
||||||
|
q.id IS NULL
|
||||||
|
RETURNING quoted_post_id
|
||||||
|
", post_id: post.id, post_number: post_number, topic_id: topic_id
|
||||||
|
|
||||||
# It would be so much nicer if we used post_id in quotes
|
results = results.to_a
|
||||||
results = exec_sql "INSERT INTO quoted_posts(post_id, quoted_post_id, created_at, updated_at)
|
ids << results[0]["quoted_post_id"].to_i if results.length > 0
|
||||||
SELECT :post_id, p.id, current_timestamp, current_timestamp
|
rescue ActiveRecord::RecordNotUnique, PG::UniqueViolation
|
||||||
FROM posts p
|
# it's fine
|
||||||
LEFT JOIN quoted_posts q on q.post_id = :post_id AND q.quoted_post_id = p.id
|
|
||||||
WHERE post_number = :post_number AND
|
|
||||||
topic_id = :topic_id AND
|
|
||||||
q.id IS NULL
|
|
||||||
RETURNING quoted_post_id
|
|
||||||
", post_id: post.id, post_number: post_number, topic_id: topic_id
|
|
||||||
|
|
||||||
results = results.to_a
|
|
||||||
|
|
||||||
if results.length > 0
|
|
||||||
ids << results[0]["quoted_post_id"].to_i
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -15,9 +15,15 @@ describe QuotedPost do
|
|||||||
post1 = Fabricate(:post)
|
post1 = Fabricate(:post)
|
||||||
post2 = Fabricate(:post)
|
post2 = Fabricate(:post)
|
||||||
|
|
||||||
post2.cooked = <<HTML
|
post2.cooked = <<-HTML
|
||||||
<aside class="quote" data-post="#{post1.post_number}" data-topic="#{post1.topic_id}"><div class="title"><div class="quote-controls"></div><img width="20" height="20" src="/user_avatar/meta.discourse.org/techapj/20/3281.png" class="avatar">techAPJ:</div><blockquote><p>When the user will v</p></blockquote></aside>
|
<aside class="quote" data-post="#{post1.post_number}" data-topic="#{post1.topic_id}">
|
||||||
HTML
|
<div class="title">
|
||||||
|
<div class="quote-controls"></div>
|
||||||
|
<img width="20" height="20" src="/user_avatar/meta.discourse.org/techapj/20/3281.png" class="avatar">techAPJ:
|
||||||
|
</div>
|
||||||
|
<blockquote><p>When the user will v</p></blockquote>
|
||||||
|
</aside>
|
||||||
|
HTML
|
||||||
|
|
||||||
QuotedPost.create!(post_id: post2.id, quoted_post_id: 999)
|
QuotedPost.create!(post_id: post2.id, quoted_post_id: 999)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user