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
|
||||
|
||||
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)
|
||||
end
|
||||
|
||||
|
|
|
@ -507,6 +507,7 @@ class Post < ActiveRecord::Base
|
|||
}
|
||||
args[:image_sizes] = image_sizes if image_sizes.present?
|
||||
args[:invalidate_oneboxes] = true if invalidate_oneboxes.present?
|
||||
args[:cooking_options] = self.cooking_options
|
||||
Jobs.enqueue(:process_post, args)
|
||||
DiscourseEvent.trigger(:after_trigger_post_process, self)
|
||||
end
|
||||
|
|
|
@ -11,7 +11,11 @@ class CookedPostProcessor
|
|||
@opts = opts
|
||||
@post = post
|
||||
@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 = {}
|
||||
end
|
||||
|
||||
|
|
|
@ -176,7 +176,7 @@ class PostCreator
|
|||
cooking_options = post.cooking_options || {}
|
||||
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.last_version_at ||= Time.now
|
||||
end
|
||||
|
|
|
@ -118,9 +118,9 @@ describe CookedPostProcessor do
|
|||
|
||||
it "generates overlay information" do
|
||||
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>
|
||||
</div></a></div>'
|
||||
</div></a></div></p>'
|
||||
expect(cpp).to be_dirty
|
||||
end
|
||||
|
||||
|
@ -145,9 +145,9 @@ describe CookedPostProcessor do
|
|||
|
||||
it "generates overlay information" do
|
||||
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>
|
||||
</div></a></div>'
|
||||
</div></a></div></p>'
|
||||
expect(cpp).to be_dirty
|
||||
end
|
||||
|
||||
|
@ -341,9 +341,7 @@ describe CookedPostProcessor do
|
|||
|
||||
it "uses schemaless url for uploads" do
|
||||
cpp.optimize_urls
|
||||
expect(cpp.html).to match_html '<a href="//test.localhost/uploads/default/2/2345678901234567.jpg">Link</a>
|
||||
<img src="//test.localhost/uploads/default/1/1234567890123456.jpg"><a href="http://www.google.com">Google</a>
|
||||
<img src="http://foo.bar/image.png">'
|
||||
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>'
|
||||
end
|
||||
|
||||
context "when CDN is enabled" do
|
||||
|
@ -351,17 +349,13 @@ describe CookedPostProcessor do
|
|||
it "does use schemaless CDN url for http uploads" do
|
||||
Rails.configuration.action_controller.stubs(:asset_host).returns("http://my.cdn.com")
|
||||
cpp.optimize_urls
|
||||
expect(cpp.html).to match_html '<a href="//my.cdn.com/uploads/default/2/2345678901234567.jpg">Link</a>
|
||||
<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">'
|
||||
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>'
|
||||
end
|
||||
|
||||
it "does not use schemaless CDN url for https uploads" do
|
||||
Rails.configuration.action_controller.stubs(:asset_host).returns("https://my.cdn.com")
|
||||
cpp.optimize_urls
|
||||
expect(cpp.html).to match_html '<a href="https://my.cdn.com/uploads/default/2/2345678901234567.jpg">Link</a>
|
||||
<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">'
|
||||
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>'
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -460,12 +460,8 @@ This is a link http://example.com"
|
|||
|
||||
def fill_email(mail, from, to, body = nil, subject = nil)
|
||||
result = mail.gsub("FROM", from).gsub("TO", to)
|
||||
if body
|
||||
result.gsub!(/Hey.*/m, body)
|
||||
end
|
||||
if subject
|
||||
result.sub!(/We .*/, subject)
|
||||
end
|
||||
result.gsub!(/Hey.*/m, body) if body
|
||||
result.sub!(/We .*/, subject) if subject
|
||||
result
|
||||
end
|
||||
|
||||
|
|
|
@ -445,7 +445,7 @@ describe PostCreator do
|
|||
raw: raw,
|
||||
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
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,6 +12,7 @@ Fabricator(:post_with_long_raw_content, from: :post) do
|
|||
end
|
||||
|
||||
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>'
|
||||
end
|
||||
|
||||
|
@ -53,44 +54,44 @@ Fabricator(:post_with_plenty_of_images, from: :post) do
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
Fabricator(:post_with_unsized_images, from: :post) do
|
||||
cooked '
|
||||
raw '
|
||||
<img src="http://foo.bar/image.png">
|
||||
<img src="/uploads/default/1/1234567890123456.jpg">
|
||||
'
|
||||
end
|
||||
|
||||
Fabricator(:post_with_image_urls, from: :post) do
|
||||
cooked '
|
||||
raw '
|
||||
<img src="http://foo.bar/image.png">
|
||||
<img src="http://domain.com/picture.jpg" width="50" height="42">
|
||||
'
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
Fabricator(:post_with_uploads, from: :post) do
|
||||
cooked '
|
||||
raw '
|
||||
<a href="/uploads/default/2/2345678901234567.jpg">Link</a>
|
||||
<img src="/uploads/default/1/1234567890123456.jpg">
|
||||
'
|
||||
end
|
||||
|
||||
Fabricator(:post_with_uploads_and_links, from: :post) do
|
||||
cooked '
|
||||
raw '
|
||||
<a href="/uploads/default/2/2345678901234567.jpg">Link</a>
|
||||
<img src="/uploads/default/1/1234567890123456.jpg">
|
||||
<a href="http://www.google.com">Google</a>
|
||||
|
|
Loading…
Reference in New Issue