Attachment_fu: do not reload thumbnails

I have a nice little “photo” class that has attached images. When I go to a page to sort the order of photos, it repeats, although each photo sets a new “sort” value and saves it. All is good so far.

The problem is that I noticed that this is a rather slow behavior. It turns out attachment_fu reloads the thumbnail every time it is saved - regardless of whether there is new image data to work with.

Obviously, this system is well thought out, so I can only assume that there is a condition for this situation. How do I tell the attachment_fu function not to restore thumbnails when it doesn't work?

Thanks, --Matchu

Edit: I just remembered that for this particular situation, I can use update_attribute to evade all validations and other callbacks. However, this is not a very viable answer to the whole big scenario. What am I missing?

+3
source share
2 answers

I went and hacked a little attachment_fu file and rewrote the behavior save_attachment?. To a large extent, I have added several new conditions: in addition to the existing temp file, one of the following should be true:

  • The file for the image no longer exists (attribute is used full_filename).
  • Image data has been explicitly updated using the method uploaded_data=.
  • .

: , , . , , ; , .

+3

, , :

http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/709d97e06b373786

, Matchu, , attachment_fu. , Matchu save_attachment? . , , , , , attachment_fu...

Update

Matchu ( ) , , , .

save_attachment? attachment_fu/attachment_fu.rb:

def save_attachment?
  return false unless (thumbnail || !full_filename || @active_upload) #added
  File.file?(temp_path.to_s)
end

... , . , uploaded_data = setter ( - , , / noob), uploaded_data = @active_upload:

def uploaded_data=(file_data)
  return nil if file_data.nil? || file_data.size == 0
  self.content_type = file_data.content_type
  self.filename     = file_data.original_filename if respond_to?(:filename)
  @active_upload=true # added
  if file_data.is_a?(StringIO)
    file_data.rewind
    self.temp_data = file_data.read
  else
    self.temp_path = file_data
  end
end

, , - , , .

0

Source: https://habr.com/ru/post/1709143/


All Articles