carrierwaveuploader / carrierwave-mongoid

Mongoid support for CarrierWave
MIT License
355 stars 165 forks source link

Anyway to clear cache when calling .present? #197

Open namila opened 4 years ago

namila commented 4 years ago

Environment details ruby 2.6.2 rails 5.1 carrierwave 2.0 carrierwave-mongoid 1.3

Steps to reproduce

take an object which has a file in s3 and call offer.offer_pdf.present?

expected result : true, actual_result: true

delete that file from the s3 bucket and call the same method again offer.offer_pdf.present?

expected result: false, actual_result: true

I suspect the result of the "#present?" is cached and the actual state is not reflected when calling it again. Is there any way to clear this cache so I can get the current status of the file? (I tried calling #reload on the offer object, but still it did not reflect the actual status of the file) I raised the same question under fog repo, they feel there should be a way to achieve this using CarrierWave (https://github.com/fog/fog/issues/4029)

leoarnold commented 3 years ago

@namila The method #offer_url is not from carrierwave-mongoid. It is defined by carrierwave itself and not overridden by this gem:

https://github.com/carrierwaveuploader/carrierwave/blob/3084b24257dd309ee00ff350067c8c6e985ad1bc/lib/carrierwave/mount.rb#L149-L151

Tracing the method call down to the fog connector leads to the actual implementation:

https://github.com/carrierwaveuploader/carrierwave/blob/3084b24257dd309ee00ff350067c8c6e985ad1bc/lib/carrierwave/storage/fog.rb#L419-L425

tl;dr: When you call offer.offer_url.present? you are not checking whether the actual remote file is available, but merely whether carrierwave was able to generate a URL for the location where the file should be.

@rmm5t Close issue as "3rd party issue"?

leoarnold commented 3 years ago

I just noticed: offer.offer.file.exists? may do the requested.