Hi,
I have made an app for a friend running on heroku,
www.wafflehearts.com,
which uses dragonfly for the images. I have been seeing issues with
page loads of the main page, and sometimes it takes over 30 seconds
which means that the user ends up with an error instead of the actual
page.
I am going to try to include all the relevant information, but please
feel free to ask for additional details that could help debug why the
image loading/generation is slowing down things so much
==== config/initializers/dragonfly.rb ====
require 'dragonfly'
app = Dragonfly[:images]
app.configure_with(:imagemagick)
app.configure_with(:rails)
app.configure_with(:heroku, 'anne-website') if Rails.env.production?
app.define_macro(ActiveRecord::Base, :image_accessor)
------------------------------------------------------------
==== config/environments/production.rb ====
Annebeaubien::Application.configure do
config.cache_classes = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = false
config.assets.compress = true
config.assets.compile = false
config.assets.digest = true
<…>
------------------------------------------------------------
==== config/application.rb ====
module Annebeaubien
class Application < Rails::Application
<…>
config.assets.enabled = true
config.assets.version = '1.0'
config.assets.initialize_on_precompile = false
config.middleware.insert 0, 'Dragonfly::Middleware', :images
end
end
------------------------------------------------------------
==== app/model/recipe.rb ====
class Recipe < ActiveRecord::Base
image_accessor :cover_image do
storage_path{|a| "recipes/images/#{Time.now.iso8601.gsub(":",
"_")}/#{rand(100)}-#{CGI.escape title}.#{a.format}" }
end
<…>
------------------------------------------------------------
==== app/views/recipe/index.html.erb ====
<% for recipe in @recipes %>
< … >
<% if recipe.cover_image_uid %>
<% image = recipe.cover_image.thumb('150x150') %>
<%= link_to image_tag(image.url, {:height => image.height, :width =>
image.width, :class => "align-left"}), recipe_url %>
<…>
------------------------------------------------------------
Apologies if some of the configuration/code provided is not relevant,
but I figured I would rather err on the side of too much information.
I am wondering whether this could be a cache issue, or something to do
with me requesting the width and height of the thumbs?
I used to do:
==== app/views/recipe/index.html.erb ====
<% for recipe in @recipes %>
< … >
<% if recipe.cover_image_uid %>
<%= link_to image_tag(recipe.cover_image.thumb('150x150').url,
{:height => recipe.cover_image.thumb('150x150').height, :width =>
recipe.cover_image.thumb('150x150').width, :class => "align-left"}),
recipe_url %>
<…>
------------------------------------------------------------
which was causing the pages to fail to load. As you can see, I
optimized that a bit which reduced the page loading time to ~10-15
sec, but that still seems very slow, and I am hoping with your help I
can speed this up. Unless I can figure this out, my next step would be
to regenerate the thumb images of this size, but I was hoping to avoid
having multiple versions of the images when using dragonfly.
Thanks for any and all suggestions.
Chris