2

我加载我的图像,第一次它会convert在它们上运行,所以它有点慢。但我希望它永远不会convert再在它们身上运行,但 DragonFly 一遍又一遍地做(在开发模式下)。

2014-01-15 14:10:45.587 [fyi] Started GET "/media/W1siZiIsIjIwMTMvMTEvMTEvMTkvNTAvMDAvNTg3L2JsaW5kYmFyYmVyX2ZhY2lhbGNsZWFuc2VyLmpwZyJdLFsicCIsInRodW1iIiwiOTIweDkyMD4iXSxbInAiLCJlbmNvZGUiLCJqcGciLCItcXVhbGl0eSA0MCJdXQ/blindbarber-facialcleanser.jpg" for 127.0.0.1 at 2014-01-15 14:10:45 -0500 (pid:73447)
2014-01-15 14:10:47.149 [meh] DRAGONFLY: shell command: 'convert' '/var/folders/42/z4r6cjj10vb5c6zvtwb0m9000000gn/T/dragonfly20140115-73447-1ti4jze' '-resize' '920x920>' '/var/folders/42/z4r6cjj10vb5c6zvtwb0m9000000gn/T/dragonfly20140115-73447-fvdfam.jpg' (pid:73447)
2014-01-15 14:10:47.700 [meh] DRAGONFLY: shell command: 'convert' '/var/folders/42/z4r6cjj10vb5c6zvtwb0m9000000gn/T/dragonfly20140115-73447-fvdfam.jpg' '-quality' '40' '/var/folders/42/z4r6cjj10vb5c6zvtwb0m9000000gn/T/dragonfly20140115-73447-e10r7h.jpg' (pid:73447)
2014-01-15 14:10:47.804 [fyi] DRAGONFLY: GET /media/W1siZiIsIjIwMTMvMTEvMTEvMTkvNTAvMDAvNTg3L2JsaW5kYmFyYmVyX2ZhY2lhbGNsZWFuc2VyLmpwZyJdLFsicCIsInRodW1iIiwiOTIweDkyMD4iXSxbInAiLCJlbmNvZGUiLCJqcGciLCItcXVhbGl0eSA0MCJdXQ/blindbarber-facialcleanser.jpg 200 (pid:73447)
2014-01-15 14:10:47.807 [meh] Cache write: d857888f4b9a786a815372039d952e203c056795 (pid:73447)
2014-01-15 14:10:47.825 [meh] Cache read: d857888f4b9a786a815372039d952e203c056795 (pid:73447)
2014-01-15 14:10:47.826 [meh] Cache read: http://localhost:3000/media/W1siZiIsIjIwMTMvMTEvMTEvMTkvNTAvMDAvNTg3L2JsaW5kYmFyYmVyX2ZhY2lhbGNsZWFuc2VyLmpwZyJdLFsicCIsInRodW1iIiwiOTIweDkyMD4iXSxbInAiLCJlbmNvZGUiLCJqcGciLCItcXVhbGl0eSA0MCJdXQ/blindbarber-facialcleanser.jpg? (pid:73447)
2014-01-15 14:10:47.827 [meh] Cache write: http://localhost:3000/media/W1siZiIsIjIwMTMvMTEvMTEvMTkvNTAvMDAvNTg3L2JsaW5kYmFyYmVyX2ZhY2lhbGNsZWFuc2VyLmpwZyJdLFsicCIsInRodW1iIiwiOTIweDkyMD4iXSxbInAiLCJlbmNvZGUiLCJqcGciLCItcXVhbGl0eSA0MCJdXQ/blindbarber-facialcleanser.jpg? (pid:73447)

但是对于每个请求,它都会再次转换图像,知道为什么吗?

PS:我的dragonfly.rb

4

1 回答 1

0

实际的解决方案是启用 Rack Cache (in config/environments/development.rb):

  config.action_dispatch.rack_cache = {
    metastore: 'file:tmp/cache/rack/meta',
    entitystore: 'file:tmp/cache/rack/body'
  }

并且要意识到每个image.width,image.height等...实际上都会调用一个convert命令。因此,如果您想经常获取此信息,最好将其存储在您的模型中:

  create_table "images", force: true do |t|
    # ...
    t.string   "image_uid"
    t.string   "image_name"
    t.integer  "image_height"
    t.integer  "image_width"
  end

在你的模型中:

  before_save :update_image_fields
  def update_image_fields
    if image
      self.image_width = image.width
      self.image_height = image.height
    else
      self.image_width = self.image_height = 0
    end

    true
  end
于 2014-10-21T17:52:52.970 回答