Merge pull request #4824 from tgxworld/fix_optimize_image_timeout

Fix optimize image timeout
This commit is contained in:
Guo Xiang Tan 2017-04-20 15:53:43 +08:00 committed by GitHub
commit 94c7be3ca6
4 changed files with 18 additions and 10 deletions

View File

@ -2,10 +2,11 @@ skip_missing_workers: true
allow_lossy: false
# PNG
advpng: false
optipng:
optipng:
level: 2
pngcrush: false
pngout: false
pngquant: false
# JPG
jpegrecompress: false
timeout: 15

View File

@ -66,7 +66,9 @@ gem 'unf', require: false
gem 'email_reply_trimmer', '0.1.6'
gem 'image_optim'
# TODO Use official image_optim gem once https://github.com/toy/image_optim/pull/149
# is merged.
gem 'discourse_image_optim', require: 'image_optim'
gem 'multi_json'
gem 'mustache'
gem 'nokogiri'

View File

@ -79,6 +79,12 @@ GEM
discourse-qunit-rails (0.0.9)
railties
discourse_fastimage (2.0.3)
discourse_image_optim (0.24.4)
exifr (~> 1.2, >= 1.2.2)
fspath (~> 3.0)
image_size (~> 1.5)
in_threads (~> 1.3)
progress (~> 3.0, >= 3.0.1)
domain_name (0.5.25)
unf (>= 0.0.5, < 1.0.0)
email_reply_trimmer (0.1.6)
@ -126,12 +132,6 @@ GEM
domain_name (~> 0.5)
http_accept_language (2.0.5)
i18n (0.8.1)
image_optim (0.24.2)
exifr (~> 1.2, >= 1.2.2)
fspath (~> 3.0)
image_size (~> 1.5)
in_threads (~> 1.3)
progress (~> 3.0, >= 3.0.1)
image_size (1.5.0)
in_threads (1.4.0)
jmespath (1.3.1)
@ -405,6 +405,7 @@ DEPENDENCIES
certified
discourse-qunit-rails
discourse_fastimage (= 2.0.3)
discourse_image_optim
email_reply_trimmer (= 0.1.6)
ember-handlebars-template (= 0.7.5)
ember-rails (= 0.18.5)
@ -423,7 +424,6 @@ DEPENDENCIES
hiredis
htmlentities
http_accept_language (~> 2.0.5)
image_optim
listen
logster
lru_redux

View File

@ -155,7 +155,12 @@ class Upload < ActiveRecord::Base
# optimize image (except GIFs, SVGs and large PNGs)
if should_optimize?(file.path, [w, h])
ImageOptim.new.optimize_image!(file.path) rescue nil
begin
ImageOptim.new.optimize_image!(file.path)
rescue ImageOptim::Worker::TimeoutExceeded
# Don't optimize if it takes too long
Rails.logger.warn("ImageOptim timed out while optimizing #{filename}")
end
# update the file size
filesize = File.size(file.path)
end