FIX: timing issue with edits and cook post processing
This commit is contained in:
parent
3aaa9a8722
commit
54d6d24cbf
|
@ -14,7 +14,9 @@ module Jobs
|
||||||
recooked = nil
|
recooked = nil
|
||||||
|
|
||||||
if args[:cook].present?
|
if args[:cook].present?
|
||||||
recooked = post.cook(post.raw, topic_id: post.topic_id)
|
cooking_options = args[:cooking_options] || {}
|
||||||
|
cooking_options[:topic_id] = post.topic_id
|
||||||
|
recooked = post.cook(post.raw, cooking_options.symbolize_keys)
|
||||||
post.update_column(:cooked, recooked)
|
post.update_column(:cooked, recooked)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -507,6 +507,7 @@ class Post < ActiveRecord::Base
|
||||||
}
|
}
|
||||||
args[:image_sizes] = image_sizes if image_sizes.present?
|
args[:image_sizes] = image_sizes if image_sizes.present?
|
||||||
args[:invalidate_oneboxes] = true if invalidate_oneboxes.present?
|
args[:invalidate_oneboxes] = true if invalidate_oneboxes.present?
|
||||||
|
args[:cooking_options] = self.cooking_options
|
||||||
Jobs.enqueue(:process_post, args)
|
Jobs.enqueue(:process_post, args)
|
||||||
DiscourseEvent.trigger(:after_trigger_post_process, self)
|
DiscourseEvent.trigger(:after_trigger_post_process, self)
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,7 +11,11 @@ class CookedPostProcessor
|
||||||
@opts = opts
|
@opts = opts
|
||||||
@post = post
|
@post = post
|
||||||
@previous_cooked = (@post.cooked || "").dup
|
@previous_cooked = (@post.cooked || "").dup
|
||||||
@doc = Nokogiri::HTML::fragment(post.cooked)
|
# NOTE: we re-cook the post here in order to prevent timing issues with edits
|
||||||
|
# cf. https://meta.discourse.org/t/edit-of-rebaked-post-doesnt-show-in-html-only-in-raw/33815/6
|
||||||
|
cooking_options = post.cooking_options || opts[:cooking_options] || {}
|
||||||
|
cooking_options[:topic_id] = post.topic_id
|
||||||
|
@doc = Nokogiri::HTML::fragment(post.cook(post.raw, cooking_options.symbolize_keys))
|
||||||
@size_cache = {}
|
@size_cache = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -176,7 +176,7 @@ class PostCreator
|
||||||
cooking_options = post.cooking_options || {}
|
cooking_options = post.cooking_options || {}
|
||||||
cooking_options[:topic_id] = post.topic_id
|
cooking_options[:topic_id] = post.topic_id
|
||||||
|
|
||||||
post.cooked ||= post.cook(post.raw, cooking_options)
|
post.cooked ||= post.cook(post.raw, cooking_options.symbolize_keys)
|
||||||
post.sort_order = post.post_number
|
post.sort_order = post.post_number
|
||||||
post.last_version_at ||= Time.now
|
post.last_version_at ||= Time.now
|
||||||
end
|
end
|
||||||
|
|
|
@ -118,9 +118,9 @@ describe CookedPostProcessor do
|
||||||
|
|
||||||
it "generates overlay information" do
|
it "generates overlay information" do
|
||||||
cpp.post_process_images
|
cpp.post_process_images
|
||||||
expect(cpp.html).to match_html '<div class="lightbox-wrapper"><a data-download-href="/uploads/default/e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98" href="/uploads/default/1/1234567890123456.jpg" class="lightbox" title="logo.png"><img src="/uploads/default/optimized/1X/e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98_1_690x1380.png" width="690" height="1380"><div class="meta">
|
expect(cpp.html).to match_html '<p><div class="lightbox-wrapper"><a data-download-href="/uploads/default/e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98" href="/uploads/default/1/1234567890123456.jpg" class="lightbox" title="logo.png"><img src="/uploads/default/optimized/1X/e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98_1_690x1380.png" width="690" height="1380"><div class="meta">
|
||||||
<span class="filename">logo.png</span><span class="informations">1000x2000 1.21 KB</span><span class="expand"></span>
|
<span class="filename">logo.png</span><span class="informations">1000x2000 1.21 KB</span><span class="expand"></span>
|
||||||
</div></a></div>'
|
</div></a></div></p>'
|
||||||
expect(cpp).to be_dirty
|
expect(cpp).to be_dirty
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -145,9 +145,9 @@ describe CookedPostProcessor do
|
||||||
|
|
||||||
it "generates overlay information" do
|
it "generates overlay information" do
|
||||||
cpp.post_process_images
|
cpp.post_process_images
|
||||||
expect(cpp.html).to match_html '<div class="lightbox-wrapper"><a data-download-href="/uploads/default/e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98" href="/uploads/default/1/1234567890123456.jpg" class="lightbox" title="WAT"><img src="/uploads/default/optimized/1X/e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98_1_690x1380.png" title="WAT" width="690" height="1380"><div class="meta">
|
expect(cpp.html).to match_html '<p><div class="lightbox-wrapper"><a data-download-href="/uploads/default/e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98" href="/uploads/default/1/1234567890123456.jpg" class="lightbox" title="WAT"><img src="/uploads/default/optimized/1X/e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98_1_690x1380.png" title="WAT" width="690" height="1380"><div class="meta">
|
||||||
<span class="filename">WAT</span><span class="informations">1000x2000 1.21 KB</span><span class="expand"></span>
|
<span class="filename">WAT</span><span class="informations">1000x2000 1.21 KB</span><span class="expand"></span>
|
||||||
</div></a></div>'
|
</div></a></div></p>'
|
||||||
expect(cpp).to be_dirty
|
expect(cpp).to be_dirty
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -341,9 +341,7 @@ describe CookedPostProcessor do
|
||||||
|
|
||||||
it "uses schemaless url for uploads" do
|
it "uses schemaless url for uploads" do
|
||||||
cpp.optimize_urls
|
cpp.optimize_urls
|
||||||
expect(cpp.html).to match_html '<a href="//test.localhost/uploads/default/2/2345678901234567.jpg">Link</a>
|
expect(cpp.html).to match_html '<p><a href="//test.localhost/uploads/default/2/2345678901234567.jpg">Link</a><br><img src="//test.localhost/uploads/default/1/1234567890123456.jpg"><br><a href="http://www.google.com" rel="nofollow">Google</a><br><img src="http://foo.bar/image.png"></p>'
|
||||||
<img src="//test.localhost/uploads/default/1/1234567890123456.jpg"><a href="http://www.google.com">Google</a>
|
|
||||||
<img src="http://foo.bar/image.png">'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when CDN is enabled" do
|
context "when CDN is enabled" do
|
||||||
|
@ -351,17 +349,13 @@ describe CookedPostProcessor do
|
||||||
it "does use schemaless CDN url for http uploads" do
|
it "does use schemaless CDN url for http uploads" do
|
||||||
Rails.configuration.action_controller.stubs(:asset_host).returns("http://my.cdn.com")
|
Rails.configuration.action_controller.stubs(:asset_host).returns("http://my.cdn.com")
|
||||||
cpp.optimize_urls
|
cpp.optimize_urls
|
||||||
expect(cpp.html).to match_html '<a href="//my.cdn.com/uploads/default/2/2345678901234567.jpg">Link</a>
|
expect(cpp.html).to match_html '<p><a href="//my.cdn.com/uploads/default/2/2345678901234567.jpg">Link</a><br><img src="//my.cdn.com/uploads/default/1/1234567890123456.jpg"><br><a href="http://www.google.com" rel="nofollow">Google</a><br><img src="http://foo.bar/image.png"></p>'
|
||||||
<img src="//my.cdn.com/uploads/default/1/1234567890123456.jpg"><a href="http://www.google.com">Google</a>
|
|
||||||
<img src="http://foo.bar/image.png">'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not use schemaless CDN url for https uploads" do
|
it "does not use schemaless CDN url for https uploads" do
|
||||||
Rails.configuration.action_controller.stubs(:asset_host).returns("https://my.cdn.com")
|
Rails.configuration.action_controller.stubs(:asset_host).returns("https://my.cdn.com")
|
||||||
cpp.optimize_urls
|
cpp.optimize_urls
|
||||||
expect(cpp.html).to match_html '<a href="https://my.cdn.com/uploads/default/2/2345678901234567.jpg">Link</a>
|
expect(cpp.html).to match_html '<p><a href="https://my.cdn.com/uploads/default/2/2345678901234567.jpg">Link</a><br><img src="https://my.cdn.com/uploads/default/1/1234567890123456.jpg"><br><a href="http://www.google.com" rel="nofollow">Google</a><br><img src="http://foo.bar/image.png"></p>'
|
||||||
<img src="https://my.cdn.com/uploads/default/1/1234567890123456.jpg"><a href="http://www.google.com">Google</a>
|
|
||||||
<img src="http://foo.bar/image.png">'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -460,12 +460,8 @@ This is a link http://example.com"
|
||||||
|
|
||||||
def fill_email(mail, from, to, body = nil, subject = nil)
|
def fill_email(mail, from, to, body = nil, subject = nil)
|
||||||
result = mail.gsub("FROM", from).gsub("TO", to)
|
result = mail.gsub("FROM", from).gsub("TO", to)
|
||||||
if body
|
result.gsub!(/Hey.*/m, body) if body
|
||||||
result.gsub!(/Hey.*/m, body)
|
result.sub!(/We .*/, subject) if subject
|
||||||
end
|
|
||||||
if subject
|
|
||||||
result.sub!(/We .*/, subject)
|
|
||||||
end
|
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -445,7 +445,7 @@ describe PostCreator do
|
||||||
raw: raw,
|
raw: raw,
|
||||||
cooking_options: { traditional_markdown_linebreaks: true })
|
cooking_options: { traditional_markdown_linebreaks: true })
|
||||||
|
|
||||||
Post.any_instance.expects(:cook).with(raw, has_key(:traditional_markdown_linebreaks)).returns(raw)
|
Post.any_instance.expects(:cook).with(raw, has_key(:traditional_markdown_linebreaks)).twice.returns(raw)
|
||||||
creator.create
|
creator.create
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,6 +12,7 @@ Fabricator(:post_with_long_raw_content, from: :post) do
|
||||||
end
|
end
|
||||||
|
|
||||||
Fabricator(:post_with_youtube, from: :post) do
|
Fabricator(:post_with_youtube, from: :post) do
|
||||||
|
raw 'http://www.youtube.com/watch?v=9bZkp7q19f0'
|
||||||
cooked '<p><a href="http://www.youtube.com/watch?v=9bZkp7q19f0" class="onebox" target="_blank">http://www.youtube.com/watch?v=9bZkp7q19f0</a></p>'
|
cooked '<p><a href="http://www.youtube.com/watch?v=9bZkp7q19f0" class="onebox" target="_blank">http://www.youtube.com/watch?v=9bZkp7q19f0</a></p>'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -53,44 +54,44 @@ Fabricator(:post_with_plenty_of_images, from: :post) do
|
||||||
end
|
end
|
||||||
|
|
||||||
Fabricator(:post_with_uploaded_image, from: :post) do
|
Fabricator(:post_with_uploaded_image, from: :post) do
|
||||||
cooked '<img src="/uploads/default/2/3456789012345678.png" width="1500" height="2000">'
|
raw '<img src="/uploads/default/2/3456789012345678.png" width="1500" height="2000">'
|
||||||
end
|
end
|
||||||
|
|
||||||
Fabricator(:post_with_an_attachment, from: :post) do
|
Fabricator(:post_with_an_attachment, from: :post) do
|
||||||
cooked '<a class="attachment" href="/uploads/default/186/66b3ed1503efc936.zip">archive.zip</a>'
|
raw '<a class="attachment" href="/uploads/default/186/66b3ed1503efc936.zip">archive.zip</a>'
|
||||||
end
|
end
|
||||||
|
|
||||||
Fabricator(:post_with_unsized_images, from: :post) do
|
Fabricator(:post_with_unsized_images, from: :post) do
|
||||||
cooked '
|
raw '
|
||||||
<img src="http://foo.bar/image.png">
|
<img src="http://foo.bar/image.png">
|
||||||
<img src="/uploads/default/1/1234567890123456.jpg">
|
<img src="/uploads/default/1/1234567890123456.jpg">
|
||||||
'
|
'
|
||||||
end
|
end
|
||||||
|
|
||||||
Fabricator(:post_with_image_urls, from: :post) do
|
Fabricator(:post_with_image_urls, from: :post) do
|
||||||
cooked '
|
raw '
|
||||||
<img src="http://foo.bar/image.png">
|
<img src="http://foo.bar/image.png">
|
||||||
<img src="http://domain.com/picture.jpg" width="50" height="42">
|
<img src="http://domain.com/picture.jpg" width="50" height="42">
|
||||||
'
|
'
|
||||||
end
|
end
|
||||||
|
|
||||||
Fabricator(:post_with_large_image, from: :post) do
|
Fabricator(:post_with_large_image, from: :post) do
|
||||||
cooked '<img src="/uploads/default/1/1234567890123456.jpg">'
|
raw '<img src="/uploads/default/1/1234567890123456.jpg">'
|
||||||
end
|
end
|
||||||
|
|
||||||
Fabricator(:post_with_large_image_and_title, from: :post) do
|
Fabricator(:post_with_large_image_and_title, from: :post) do
|
||||||
cooked '<img src="/uploads/default/1/1234567890123456.jpg" title="WAT">'
|
raw '<img src="/uploads/default/1/1234567890123456.jpg" title="WAT">'
|
||||||
end
|
end
|
||||||
|
|
||||||
Fabricator(:post_with_uploads, from: :post) do
|
Fabricator(:post_with_uploads, from: :post) do
|
||||||
cooked '
|
raw '
|
||||||
<a href="/uploads/default/2/2345678901234567.jpg">Link</a>
|
<a href="/uploads/default/2/2345678901234567.jpg">Link</a>
|
||||||
<img src="/uploads/default/1/1234567890123456.jpg">
|
<img src="/uploads/default/1/1234567890123456.jpg">
|
||||||
'
|
'
|
||||||
end
|
end
|
||||||
|
|
||||||
Fabricator(:post_with_uploads_and_links, from: :post) do
|
Fabricator(:post_with_uploads_and_links, from: :post) do
|
||||||
cooked '
|
raw '
|
||||||
<a href="/uploads/default/2/2345678901234567.jpg">Link</a>
|
<a href="/uploads/default/2/2345678901234567.jpg">Link</a>
|
||||||
<img src="/uploads/default/1/1234567890123456.jpg">
|
<img src="/uploads/default/1/1234567890123456.jpg">
|
||||||
<a href="http://www.google.com">Google</a>
|
<a href="http://www.google.com">Google</a>
|
||||||
|
|
Loading…
Reference in New Issue