mirror of
https://github.com/discourse/discourse.git
synced 2025-02-07 06:27:14 +08:00
FEATURE: add :before_post_process_cooked hook
Also reduce amount of image downloading
This commit is contained in:
parent
6c04eb911d
commit
646c6eb7cd
|
@ -29,6 +29,7 @@ class CookedPostProcessor
|
||||||
|
|
||||||
def post_process(bypass_bump = false)
|
def post_process(bypass_bump = false)
|
||||||
DistributedMutex.synchronize("post_process_#{@post.id}") do
|
DistributedMutex.synchronize("post_process_#{@post.id}") do
|
||||||
|
DiscourseEvent.trigger(:before_post_process_cooked, @doc, @post)
|
||||||
keep_reverse_index_up_to_date
|
keep_reverse_index_up_to_date
|
||||||
post_process_images
|
post_process_images
|
||||||
post_process_oneboxes
|
post_process_oneboxes
|
||||||
|
@ -193,7 +194,14 @@ class CookedPostProcessor
|
||||||
return unless src.present?
|
return unless src.present?
|
||||||
|
|
||||||
width, height = img["width"].to_i, img["height"].to_i
|
width, height = img["width"].to_i, img["height"].to_i
|
||||||
original_width, original_height = get_size(src)
|
upload = Upload.get_from_url(src)
|
||||||
|
|
||||||
|
original_width, original_height =
|
||||||
|
if upload
|
||||||
|
[upload.width, upload.height]
|
||||||
|
else
|
||||||
|
get_size(src)
|
||||||
|
end
|
||||||
|
|
||||||
# can't reach the image...
|
# can't reach the image...
|
||||||
if original_width.nil? ||
|
if original_width.nil? ||
|
||||||
|
@ -217,7 +225,7 @@ class CookedPostProcessor
|
||||||
img["height"] = height
|
img["height"] = height
|
||||||
end
|
end
|
||||||
|
|
||||||
if upload = Upload.get_from_url(src)
|
if upload
|
||||||
upload.create_thumbnail!(width, height, crop)
|
upload.create_thumbnail!(width, height, crop)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -150,7 +150,7 @@ describe CookedPostProcessor do
|
||||||
|
|
||||||
context "with large images" do
|
context "with large images" do
|
||||||
|
|
||||||
let(:upload) { Fabricate(:upload) }
|
let(:upload) { Fabricate(:upload, width: 1750, height: 2000) }
|
||||||
let(:post) { Fabricate(:post_with_large_image) }
|
let(:post) { Fabricate(:post_with_large_image) }
|
||||||
let(:cpp) { CookedPostProcessor.new(post) }
|
let(:cpp) { CookedPostProcessor.new(post) }
|
||||||
|
|
||||||
|
@ -179,7 +179,7 @@ describe CookedPostProcessor do
|
||||||
|
|
||||||
context "with large images when using subfolders" do
|
context "with large images when using subfolders" do
|
||||||
|
|
||||||
let(:upload) { Fabricate(:upload) }
|
let(:upload) { Fabricate(:upload, width: 1750, height: 2000) }
|
||||||
let(:post) { Fabricate(:post_with_large_image_on_subfolder) }
|
let(:post) { Fabricate(:post_with_large_image_on_subfolder) }
|
||||||
let(:cpp) { CookedPostProcessor.new(post) }
|
let(:cpp) { CookedPostProcessor.new(post) }
|
||||||
let(:base_url) { "http://test.localhost/subfolder" }
|
let(:base_url) { "http://test.localhost/subfolder" }
|
||||||
|
@ -220,7 +220,7 @@ describe CookedPostProcessor do
|
||||||
|
|
||||||
context "with title" do
|
context "with title" do
|
||||||
|
|
||||||
let(:upload) { Fabricate(:upload) }
|
let(:upload) { Fabricate(:upload, width: 1750, height: 2000) }
|
||||||
let(:post) { Fabricate(:post_with_large_image_and_title) }
|
let(:post) { Fabricate(:post_with_large_image_and_title) }
|
||||||
let(:cpp) { CookedPostProcessor.new(post) }
|
let(:cpp) { CookedPostProcessor.new(post) }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user