mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
PERF: stop downloading images from post processor and lean on uploads
Previously we would unconditionally fetch all images via HTTP to grab original sizing from cooked post processor in 2 different spots. This was wasteful as we already calculate and cache this info in upload records. This also simplifies some specs and reduces use of mocks.
This commit is contained in:
@ -153,14 +153,21 @@ class CookedPostProcessor
|
||||
src = img["src"]
|
||||
return if src.blank? || is_a_hyperlink?(img) || is_svg?(img)
|
||||
|
||||
original_width, original_height = (get_size(src) || [0, 0]).map(&:to_i)
|
||||
if original_width == 0 || original_height == 0
|
||||
Rails.logger.info "Can't reach '#{src}' to get its dimension."
|
||||
return
|
||||
end
|
||||
|
||||
upload = Upload.get_from_url(src)
|
||||
|
||||
original_width, original_height = nil
|
||||
|
||||
if (upload.present?)
|
||||
original_width = upload.width || 0
|
||||
original_height = upload.height || 0
|
||||
else
|
||||
original_width, original_height = (get_size(src) || [0, 0]).map(&:to_i)
|
||||
if original_width == 0 || original_height == 0
|
||||
Rails.logger.info "Can't reach '#{src}' to get its dimension."
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
if (upload.present? && upload.animated?) || src.match?(GIF_SOURCES_REGEXP)
|
||||
img.add_class("animated")
|
||||
end
|
||||
|
Reference in New Issue
Block a user