Would it be worth resizing uploaded images (to save space)?

I’d love to know if you had any success here?
Our install is nearly 3 years old now and the server is showing 27GB used (after running cleanup). There’s quite a lot of photo uploading, often straight from phones, which means lots of multi-MB image files building up.

I’d love to be able to shrink all >1 year old images to something decent but sane, to claw some precious space back.

6개의 좋아요

I believe @neil has some code we used to do this a few times, but it was focused on older versions of Discourse where inappropriately large .png images would sometimes get saved instead of smaller .jpg images.

3개의 좋아요

The script is downsize_uploads.rb. Run it like so:

cd /var/www/discourse
RAILS_ENV=production bundle exec ruby script/downsize_uploads.rb

It will try to downsize images to be 1 megapixel or less, or you can pass in the max size you want.

The script doesn’t scope it like that, but you can easily edit the script to do so. Add .where('created_at < ?, 1.year.ago) to the query on line 10.

9개의 좋아요

@neil Could this be used for S3 image uploads as well?

1개의 좋아요

That script only works if you store the images locally. It would need to be updated to support images stored externally.

4개의 좋아요

이 코드를 내 Discourse에서 시도해 봤지만 다음과 같은 오류가 발생했습니다.

/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:50:in rescue in postgresql_connection’: FATAL: Peer authentication failed for user “discourse” (ActiveRecord::NoDatabaseError)`

참고로, 스크립트는 이제 S3에 저장된 업로드도 처리하도록 업데이트되었습니다.

6개의 좋아요