From 7f2d1736608795deb6451a892652db6457ce057d Mon Sep 17 00:00:00 2001 From: schneems 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 --- 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 5ad7ce20d..1aecc3a5d 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 675022413..c0e07337a 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'