Do you have a rough idea how long the du was taking for you? I’m not really keen on this approach to resolve the performance issue and I think there are two alternatives:
- Just use
Upload.sum(:filesize).to_i + OptimizedImage.sum(:filesize).to_ito determineuploads_used_byteslike how we do for external stores. - Introduce a background job that periodically recalculates the bytes used by uploads and cache it in Redis.
Personally, I’m more keen on (1) as it is a much simpler solution. We do lose some accuracy but we don’t need 100% accuracy here. Still it will be much better than the approximation we get from df.