FIX: Ensure no image downloads during topic thumbnail serialization

FIX: Ensure no image downloads during topic thumbnail serialization

If image uploads are missing a width/height, we re-download them to update the width/height in the database. However, this takes significant resources so we don’t want to run this logic during topic serialization.

diff --git a/app/models/topic.rb b/app/models/topic.rb
index 22307a8..d331a30 100644
--- a/app/models/topic.rb
+++ b/app/models/topic.rb
@@ -42,7 +42,7 @@ class Topic < ActiveRecord::Base
 
   def filtered_topic_thumbnails(extra_sizes: [])
     return nil unless original = image_upload
-    return nil unless original.width && original.height
+    return nil unless original.read_attribute(:width) && original.read_attribute(:height)
 
     thumbnail_sizes = Topic.thumbnail_sizes + extra_sizes
     topic_thumbnails.filter { |record| thumbnail_sizes.include?([record.max_width, record.max_height]) }
@@ -50,7 +50,7 @@ class Topic < ActiveRecord::Base
 
   def thumbnail_info(enqueue_if_missing: false, extra_sizes: [])
     return nil unless original = image_upload
-    return nil unless original.width && original.height
+    return nil unless original.read_attribute(:width) && original.read_attribute(:height)
 
     infos = []
     infos << { # Always add original

GitHub sha: f9681552

1 Like