FIX: include posts with data-orig-src attribute in have_uploads scope query.

follow-up
#1

FIX: include posts with data-orig-src attribute in have_uploads scope query.

diff --git a/app/models/post.rb b/app/models/post.rb
index 2906c61..98a7d38 100644
--- a/app/models/post.rb
+++ b/app/models/post.rb
@@ -117,7 +117,7 @@ class Post < ActiveRecord::Base
 
   scope :have_uploads, -> {
     where(
-      "(posts.cooked LIKE '%<a %' OR posts.cooked LIKE '%<img %') AND (posts.cooked LIKE ? OR posts.cooked LIKE '%/original/%' OR posts.cooked LIKE '%/optimized/%')",
+      "(posts.cooked LIKE '%<a %' OR posts.cooked LIKE '%<img %') AND (posts.cooked LIKE ? OR posts.cooked LIKE '%/original/%' OR posts.cooked LIKE '%/optimized/%' OR posts.cooked LIKE '%data-orig-src=%')",
       "%/uploads/#{RailsMultisite::ConnectionManagement.current_db}/%"
     )
   }
diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb
index b6edeb6..1b27825 100644
--- a/spec/models/post_spec.rb
+++ b/spec/models/post_spec.rb
@@ -1348,6 +1348,7 @@ describe Post do
       ids << Fabricate(:post, cooked: "A post with upload link <a href='https://cdn.example.com/original/1X/abc/defghijklmno.png'>").id
       ids << Fabricate(:post, cooked: "A post with optimized image <img src='https://cdn.example.com/bucket/optimized/1X/abc/defghijklmno.png'>").id
       Fabricate(:post, cooked: "A post with external link <a href='https://example.com/wp-content/uploads/abcdef.gif'>")
+      ids << Fabricate(:post, cooked: 'A post with missing upload <img src="https://cdn.example.com/images/transparent.png" data-orig-src="upload://defghijklmno.png">').id
       expect(Post.have_uploads.order(:id).pluck(:id)).to eq(ids)
     end
   end

GitHub sha: 0e677daa

1 Like
#2

This commit has been mentioned on Discourse Meta. There might be relevant details there:

#3

That line is getting a tad to wide. Can you put it on several lines?

1 Like
Follow Up #4