From 609d1e05cdfaa06f040d8b7453ac49a5f81abcf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Fri, 4 Jul 2014 13:26:06 +0200 Subject: [PATCH] FEATURE: optimize the hell out of letter avatars --- app/controllers/user_avatars_controller.rb | 1 - app/models/optimized_image.rb | 3 ++- lib/letter_avatar.rb | 12 ++++-------- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/app/controllers/user_avatars_controller.rb b/app/controllers/user_avatars_controller.rb index 26bc809d365..d27d2c3bc30 100644 --- a/app/controllers/user_avatars_controller.rb +++ b/app/controllers/user_avatars_controller.rb @@ -6,7 +6,6 @@ class UserAvatarsController < ApplicationController skip_before_filter :redirect_to_login_if_required, :check_xhr, :verify_authenticity_token, only: [:show, :show_letter] def refresh_gravatar - user = User.find_by(username_lower: params[:username].downcase) guardian.ensure_can_edit!(user) diff --git a/app/models/optimized_image.rb b/app/models/optimized_image.rb index c34d9632a62..08f81730944 100644 --- a/app/models/optimized_image.rb +++ b/app/models/optimized_image.rb @@ -82,7 +82,8 @@ class OptimizedImage < ActiveRecord::Base }.join(" ") `convert #{instructions}` - $?.exitstatus == 0 + + ImageOptim.new.optimize_image(to) rescue nil if $?.exitstatus == 0 end end diff --git a/lib/letter_avatar.rb b/lib/letter_avatar.rb index df1da689e69..61c80c87e82 100644 --- a/lib/letter_avatar.rb +++ b/lib/letter_avatar.rb @@ -29,7 +29,6 @@ class LetterAvatar end def generate(username, size, opts = nil) - identity = Identity.from_username(username) cache = true @@ -38,14 +37,10 @@ class LetterAvatar size = FULLSIZE if size > FULLSIZE filename = cached_path(identity, size) - if cache && File.exists?(filename) - return filename - end + return filename if cache && File.exists?(filename) fullsize = fullsize_path(identity) - if !cache || !File.exists?(fullsize) - generate_fullsize(identity) - end + generate_fullsize(identity) if !cache || !File.exists?(fullsize) OptimizedImage.resize(fullsize, filename, size, size) filename @@ -63,7 +58,6 @@ class LetterAvatar end def generate_fullsize(identity) - color = identity.color letter = identity.letter @@ -85,6 +79,8 @@ class LetterAvatar `convert #{instructions.join(" ")}` + ImageOptim.new.optimize_image(filename) rescue nil + filename end