Fixes issue ##2504 - Login into Zammad not possible, application server puma will raise 100% or more cpu.

This commit is contained in:
Martin Edenhofer 2019-03-05 03:52:54 +01:00
parent 909f4b7eaf
commit cdb4042961

View file

@ -281,6 +281,10 @@ returns
file.provider file.provider
end end
def self.semaphore
@semaphore ||= Mutex.new
end
private private
def image_resize(content, width) def image_resize(content, width)
@ -295,19 +299,25 @@ returns
temp_file.binmode temp_file.binmode
temp_file.write(content) temp_file.write(content)
temp_file.close temp_file.close
image = Rszr::Image.load(temp_file.path)
# do not resize image if image is smaller or already same size temp_file_resize = nil
return if image.width <= width self.class.semaphore.synchronize do
image = Rszr::Image.load(temp_file.path)
# do not resize image if new height is smaller then 7px (images # do not resize image if image is smaller or already same size
# with small height are usally usefull to resize) return if image.width <= width
ratio = image.width / width
return if image.height / ratio <= 6 # do not resize image if new height is smaller then 7px (images
# with small height are usally usefull to resize)
ratio = image.width / width
return if image.height / ratio <= 6
image.resize!(width, :auto)
temp_file_resize = ::Tempfile.new.path
image.save(temp_file_resize)
image.send(:handle).finalize!
end
image.resize!(width, :auto)
temp_file_resize = ::Tempfile.new.path
image.save(temp_file_resize)
image_resized = ::File.binread(temp_file_resize) image_resized = ::File.binread(temp_file_resize)
Cache.write(cache_key, image_resized, { expires_in: 6.months }) Cache.write(cache_key, image_resized, { expires_in: 6.months })