From d1c5d0261cbc4316f634262ff1fed2ffb87bc7b0 Mon Sep 17 00:00:00 2001 From: jthurn24 Date: Tue, 26 May 2015 11:04:34 -0500 Subject: [PATCH] Decrease Memory footprint Mime-types 2.6.1+ has a columnar store that only loads the data that is needed for a drastically reduced memory footprint. cc/ @jeremyevans @halostatue See: https://github.com/mime-types/ruby-mime-types/pull/96. [fixes #1873] --- features/step_definitions/attachment_steps.rb | 8 +++++++- lib/paperclip.rb | 9 ++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/features/step_definitions/attachment_steps.rb b/features/step_definitions/attachment_steps.rb index 5ad7ce2..1aecc3a 100644 --- a/features/step_definitions/attachment_steps.rb +++ b/features/step_definitions/attachment_steps.rb @@ -49,7 +49,13 @@ def attachment_path(filename) Then /^the attachment should have the same content type as the fixture "([^"]*)"$/ do |filename| in_current_dir do - require 'mime/types' + begin + # Use mime/types/columnar if available, for reduced memory usage + require "mime/types/columnar" + rescue LoadError + require "mime/types" + end + attachment_content_type = `bundle exec #{runner_command} "puts User.last.attachment_content_type"`.strip attachment_content_type.should == MIME::Types.type_for(filename).first.content_type end diff --git a/lib/paperclip.rb b/lib/paperclip.rb index 6750224..c0e0733 100644 --- a/lib/paperclip.rb +++ b/lib/paperclip.rb @@ -56,7 +56,14 @@ require 'paperclip/attachment_registry' require 'paperclip/filename_cleaner' require 'paperclip/rails_environment' -require 'mime/types' + +begin + # Use mime/types/columnar if available, for reduced memory usage + require "mime/types/columnar" +rescue LoadError + require "mime/types" +end + require 'mimemagic' require 'mimemagic/overlay' require 'logger'