DEV: Improve script/downsize_uploads.rb (#13508)

* Only shrink images that are used in Posts and no other models
* Don't save the upload if the size is the same
This commit is contained in:
Jarek Radosz
2021-06-24 00:09:40 +02:00
committed by GitHub
parent 60a76737dc
commit 046a875222
6 changed files with 94 additions and 77 deletions

View File

@ -35,7 +35,11 @@ def process_uploads
dimensions_count = 0
downsized_count = 0
scope = Upload.by_users.where("LOWER(extension) IN ('jpg', 'jpeg', 'gif', 'png')")
scope = Upload
.by_users
.with_no_non_post_relations
.where("LOWER(extension) IN ('jpg', 'jpeg', 'gif', 'png')")
scope = scope.where(<<-SQL, MAX_IMAGE_PIXELS)
COALESCE(width, 0) = 0 OR
COALESCE(height, 0) = 0 OR