Reputation: 1893
I am working on rails 2 application with paperclip gem to upload image on s3. some times it take long time to upload an image and some time it uploads very fast.
So problem is related to server space on s3 or my internet speed?
Upvotes: 0
Views: 703
Reputation: 3139
Check out my post on a similar question.
Basically, use Threads to make things appear faster. It won't actually make things faster, it will just run code in a separate process and won't take up time in the main code execution.
When the next page is loaded, none of the images will show unless you refresh the page again after a few seconds.
If you're saving one image at a time.
# cats_controller.rb
def create
@cat = Cat.find params[:id]
mutex = Mutex.new
Thread.new do
mutex.synchronize do
@cat.update cat_params
end
end
end
If you're uploading many images at a time
# cat.rb
def files=(array = [])
threads = []
semaphore = Mutex.new
array.each do |f|
threads << Thread.new do
semaphore.synchronize do
images.create file: f
end
end
end
end
Upvotes: 0
Reputation: 5112
The answer to your question is subjective to both code and internet connection..
for example:-
if you are using multiple styles such as:-
:styles => { :thumb => "100x100#", :small => "150x150>", :medium => "200x200" }
then..it can take time...as u are converting the images at runtime..thats why we have delayed_paperclip to get only the styles that we really need on other upcoming page and convert the rest of the styles in the background using redis
.
article has_many :photos
carefully during multiple image uploads and limit multiple uploads to 3 at a time using both js and server side validationimage#create
method and remove all unwanted code and emphasis only on creating/saving the object,rest of the things can be handled by after_create
or observer
.use rails profiler to understand and optimise the code...Upvotes: 1