Merge pull request #4679 from techAPJ/rebake-extract-links

FIX: topic links were getting dropped when post is rebaked
This commit is contained in:
Arpit Jalan 2017-01-30 16:36:15 +05:30 committed by GitHub
commit 0c6ad455a3
4 changed files with 13 additions and 17 deletions

View File

@ -33,11 +33,17 @@ module Jobs
Rails.logger.warn("Cooked post processor in FATAL state, bypassing. You need to urgently restart sidekiq\norig: #{orig_cooked}\nrecooked: #{recooked}\ncooked: #{cooked}\npost id: #{post.id}") Rails.logger.warn("Cooked post processor in FATAL state, bypassing. You need to urgently restart sidekiq\norig: #{orig_cooked}\nrecooked: #{recooked}\ncooked: #{cooked}\npost id: #{post.id}")
else else
post.update_column(:cooked, cp.html) post.update_column(:cooked, cp.html)
extract_links(post)
post.publish_change_to_clients! :revised post.publish_change_to_clients! :revised
end end
end end
end end
# onebox may have added some links, so extract them now
def extract_links(post)
TopicLink.extract_from(post)
QuotedPost.extract_from(post)
end
end end
end end

View File

@ -35,16 +35,9 @@ class CookedPostProcessor
optimize_urls optimize_urls
pull_hotlinked_images(bypass_bump) pull_hotlinked_images(bypass_bump)
grant_badges grant_badges
extract_links
end end
end end
# onebox may have added some links, so extract them now
def extract_links
TopicLink.extract_from(@post)
QuotedPost.extract_from(@post)
end
def has_emoji? def has_emoji?
(@doc.css("img.emoji") - @doc.css(".quote img")).size > 0 (@doc.css("img.emoji") - @doc.css(".quote img")).size > 0
end end

View File

@ -602,16 +602,6 @@ describe CookedPostProcessor do
end end
context "extracts links" do
let(:post) { Fabricate(:post, raw: "sam has a blog at https://samsaffron.com") }
it "always re-extracts links on post process" do
TopicLink.destroy_all
CookedPostProcessor.new(post).post_process
expect(TopicLink.count).to eq(1)
end
end
context "grant badges" do context "grant badges" do
let(:cpp) { CookedPostProcessor.new(post) } let(:cpp) { CookedPostProcessor.new(post) }

View File

@ -46,6 +46,13 @@ describe Jobs::ProcessPost do
expect(post.cooked).not_to match(/http/) expect(post.cooked).not_to match(/http/)
end end
it "always re-extracts links on post process" do
post.update_columns(raw: "sam has a blog at https://samsaffron.com")
TopicLink.destroy_all
Jobs::ProcessPost.new.execute(post_id: post.id)
expect(TopicLink.count).to eq(1)
end
end end