]> cat aescling's git repositories - mastodon.git/commitdiff
Use #any? instead of #exists? when checking media attachments (#7570)
authorEugen Rochko <eugen@zeonfederated.com>
Mon, 21 May 2018 14:01:16 +0000 (16:01 +0200)
committerGitHub <noreply@github.com>
Mon, 21 May 2018 14:01:16 +0000 (16:01 +0200)
If media_attachments are not loaded, SQL query is the same, but
the #exists? method performs SQL query even if preloaded

app/services/batched_remove_status_service.rb
app/services/fan_out_on_write_service.rb
app/services/remove_status_service.rb

index 425a11d012d7eadf7ccefe2874b13081d260b4b2..ace51a1fcc7bbd7da3d41d4e8a7c86038929bd7b 100644 (file)
@@ -81,7 +81,7 @@ class BatchedRemoveStatusService < BaseService
       redis.publish('timeline:public', payload)
       redis.publish('timeline:public:local', payload) if status.local?
 
-      if status.media_attachments.exists?
+      if status.media_attachments.any?
         redis.publish('timeline:public:media', payload)
         redis.publish('timeline:public:local:media', payload) if status.local?
       end
index b4b9986f3b68eb94bab9c6595782956c4aa3a7a1..8b3630229919c4f8cb436e71400b03881b76fc22 100644 (file)
@@ -25,7 +25,7 @@ class FanOutOnWriteService < BaseService
     return if status.reply? && status.in_reply_to_account_id != status.account_id
 
     deliver_to_public(status)
-    deliver_to_media(status) if status.media_attachments.exists?
+    deliver_to_media(status) if status.media_attachments.any?
   end
 
   private
index 53f2be6f8606f7a972ba87f0b93703ae7264ee4d..8c3e184442edafd4e4b24d0fe62f0bab069e472a 100644 (file)
@@ -20,7 +20,7 @@ class RemoveStatusService < BaseService
     remove_reblogs
     remove_from_hashtags
     remove_from_public
-    remove_from_media if status.media_attachments.exists?
+    remove_from_media if status.media_attachments.any?
     remove_from_direct if status.direct_visibility?
 
     @status.destroy!