mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Do not reset link counts when post is rebaked
This was an indentation mistake introduced in 44eba0b
. Pretty understandable, considering we are indented 8 levels deep in this method. Will follow-up with a refactor to improve this.
This commit is contained in:
parent
978f0db109
commit
37249c9a32
@ -223,34 +223,35 @@ SQL
|
|||||||
# If we can't find the route, no big deal
|
# If we can't find the route, no big deal
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Remove links that aren't there anymore
|
# Remove links that aren't there anymore
|
||||||
if added_urls.present?
|
if added_urls.present?
|
||||||
|
TopicLink.where(
|
||||||
|
"(url not in (:urls)) AND (post_id = :post_id AND NOT reflection)",
|
||||||
|
urls: added_urls, post_id: post.id
|
||||||
|
).delete_all
|
||||||
|
|
||||||
|
reflected_ids.compact!
|
||||||
|
if reflected_ids.present?
|
||||||
TopicLink.where(
|
TopicLink.where(
|
||||||
"(url not in (:urls)) AND (post_id = :post_id AND NOT reflection)",
|
"(id not in (:reflected_ids)) AND (link_post_id = :post_id AND reflection)",
|
||||||
urls: added_urls, post_id: post.id
|
reflected_ids: reflected_ids, post_id: post.id
|
||||||
).delete_all
|
).delete_all
|
||||||
|
|
||||||
reflected_ids.compact!
|
|
||||||
if reflected_ids.present?
|
|
||||||
TopicLink.where(
|
|
||||||
"(id not in (:reflected_ids)) AND (link_post_id = :post_id AND reflection)",
|
|
||||||
reflected_ids: reflected_ids, post_id: post.id
|
|
||||||
).delete_all
|
|
||||||
else
|
|
||||||
TopicLink
|
|
||||||
.where("link_post_id = :post_id AND reflection", post_id: post.id)
|
|
||||||
.delete_all
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
TopicLink
|
TopicLink
|
||||||
.where(
|
.where("link_post_id = :post_id AND reflection", post_id: post.id)
|
||||||
"(post_id = :post_id AND NOT reflection) OR (link_post_id = :post_id AND reflection)",
|
|
||||||
post_id: post.id
|
|
||||||
)
|
|
||||||
.delete_all
|
.delete_all
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
TopicLink
|
||||||
|
.where(
|
||||||
|
"(post_id = :post_id AND NOT reflection) OR (link_post_id = :post_id AND reflection)",
|
||||||
|
post_id: post.id
|
||||||
|
)
|
||||||
|
.delete_all
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Crawl a link's title after it's saved
|
# Crawl a link's title after it's saved
|
||||||
|
@ -26,15 +26,17 @@ describe TopicLink do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe 'external links' do
|
describe 'external links' do
|
||||||
before do
|
let(:post2) do
|
||||||
post = Fabricate(:post, raw: <<~RAW, user: user, topic: topic)
|
Fabricate(:post, raw: <<~RAW, user: user, topic: topic)
|
||||||
http://a.com/
|
http://a.com/
|
||||||
https://b.com/b
|
https://b.com/b
|
||||||
http://#{'a' * 200}.com/invalid
|
http://#{'a' * 200}.com/invalid
|
||||||
//b.com/#{'a' * 500}
|
//b.com/#{'a' * 500}
|
||||||
RAW
|
RAW
|
||||||
|
end
|
||||||
|
|
||||||
TopicLink.extract_from(post)
|
before do
|
||||||
|
TopicLink.extract_from(post2)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'works' do
|
it 'works' do
|
||||||
@ -45,6 +47,16 @@ describe TopicLink do
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "doesn't reset them when rebaking" do
|
||||||
|
old_ids = topic.topic_links.pluck(:id)
|
||||||
|
|
||||||
|
TopicLink.extract_from(post2)
|
||||||
|
|
||||||
|
new_ids = topic.topic_links.pluck(:id)
|
||||||
|
|
||||||
|
expect(new_ids).to contain_exactly(*old_ids)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'internal links' do
|
describe 'internal links' do
|
||||||
|
Loading…
Reference in New Issue
Block a user