我在CarrierWave Wiki中關注此文章https://github.com/carrierwaveuploader/carrierwave/wiki/How-to%3A-Add-more-files-and-remove-single-file-when-using-default-multiple-file-uploads-feature,以實現在我的系統中使用CarrierWave多上傳功能添加更多圖像和刪除圖像。Carrierwave - 添加或刪除圖像時多個圖像上傳速度太慢
是這篇文章的主要代碼是
def add_more_images(new_images)
images = @gallery.images
images += new_images
@gallery.images = images
end
def remove_image_at_index(index)
remain_images = @gallery.images # copy the array
deleted_image = remain_images.delete_at(index) # delete the target image
deleted_image.try(:remove!) # delete image from S3
@gallery.images = remain_images # re-assign back
end
它的工作原理。 但是,它太懶惰了。我已經看過在日誌和總處理時間是如下:
- 上傳1個圖像:它需要5000毫秒例如
- 添加1多個圖像:它需要8500ms(2個圖像)
- 添加1多個圖像:它需要12000ms(3個圖像)
- 刪除1個圖像:它需要8400ms(回到2個圖像)
我已經測試我的本地機器上寫入由作者這種解決方案的示例應用程序而且非常也慢。
好像CarrierWave重新上傳和重新處理所有圖像,即使我們只添加或刪除1張圖片。我認爲是因爲我們將新圖像重新分配給@gallery,以便將舊圖像作爲新圖像處理。
也有一個相關的問題在這裏https://github.com/carrierwaveuploader/carrierwave/issues/1704#issuecomment-259106600
沒有人有添加和使用CarrierWave多個上傳功能,消除圖像的任何更好的解決方案?
謝謝。