From 1290fede651b47585de7dbfe4a9b118dc9d59856 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 24 Jan 2024 06:51:09 -0500 Subject: [PATCH] Fix `Rails/WhereExists` cop in app/lib (#28862) --- .rubocop_todo.yml | 4 ---- app/lib/activitypub/activity/create.rb | 4 ++-- app/lib/delivery_failure_tracker.rb | 2 +- app/lib/feed_manager.rb | 6 +++--- app/lib/suspicious_sign_in_detector.rb | 2 +- 5 files changed, 7 insertions(+), 11 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index b62dfa72a8..302c66a16a 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -77,10 +77,6 @@ Rails/WhereExists: Exclude: - 'app/controllers/activitypub/inboxes_controller.rb' - 'app/controllers/admin/email_domain_blocks_controller.rb' - - 'app/lib/activitypub/activity/create.rb' - - 'app/lib/delivery_failure_tracker.rb' - - 'app/lib/feed_manager.rb' - - 'app/lib/suspicious_sign_in_detector.rb' - 'app/policies/status_policy.rb' - 'app/serializers/rest/announcement_serializer.rb' - 'app/workers/move_worker.rb' diff --git a/app/lib/activitypub/activity/create.rb b/app/lib/activitypub/activity/create.rb index 5a2d33c1fa..62c35d4dd3 100644 --- a/app/lib/activitypub/activity/create.rb +++ b/app/lib/activitypub/activity/create.rb @@ -320,7 +320,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity already_voted = true with_redis_lock("vote:#{replied_to_status.poll_id}:#{@account.id}") do - already_voted = poll.votes.where(account: @account).exists? + already_voted = poll.votes.exists?(account: @account) poll.votes.create!(account: @account, choice: poll.options.index(@object['name']), uri: object_uri) end @@ -406,7 +406,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity return false if local_usernames.empty? - Account.local.where(username: local_usernames).exists? + Account.local.exists?(username: local_usernames) end def tombstone_exists? diff --git a/app/lib/delivery_failure_tracker.rb b/app/lib/delivery_failure_tracker.rb index d938269829..e17b45d667 100644 --- a/app/lib/delivery_failure_tracker.rb +++ b/app/lib/delivery_failure_tracker.rb @@ -28,7 +28,7 @@ class DeliveryFailureTracker end def available? - !UnavailableDomain.where(domain: @host).exists? + !UnavailableDomain.exists?(domain: @host) end def exhausted_deliveries_days diff --git a/app/lib/feed_manager.rb b/app/lib/feed_manager.rb index 53767486ff..38a177e645 100644 --- a/app/lib/feed_manager.rb +++ b/app/lib/feed_manager.rb @@ -420,8 +420,8 @@ class FeedManager check_for_blocks = status.active_mentions.pluck(:account_id) check_for_blocks.push(status.in_reply_to_account) if status.reply? && !status.in_reply_to_account_id.nil? - should_filter = blocks_or_mutes?(receiver_id, check_for_blocks, :mentions) # Filter if it's from someone I blocked, in reply to someone I blocked, or mentioning someone I blocked (or muted) - should_filter ||= status.account.silenced? && !Follow.where(account_id: receiver_id, target_account_id: status.account_id).exists? # of if the account is silenced and I'm not following them + should_filter = blocks_or_mutes?(receiver_id, check_for_blocks, :mentions) # Filter if it's from someone I blocked, in reply to someone I blocked, or mentioning someone I blocked (or muted) + should_filter ||= status.account.silenced? && !Follow.exists?(account_id: receiver_id, target_account_id: status.account_id) # Filter if the account is silenced and I'm not following them should_filter end @@ -434,7 +434,7 @@ class FeedManager if status.reply? && status.in_reply_to_account_id != status.account_id should_filter = status.in_reply_to_account_id != list.account_id should_filter &&= !list.show_followed? - should_filter &&= !(list.show_list? && ListAccount.where(list_id: list.id, account_id: status.in_reply_to_account_id).exists?) + should_filter &&= !(list.show_list? && ListAccount.exists?(list_id: list.id, account_id: status.in_reply_to_account_id)) return !!should_filter end diff --git a/app/lib/suspicious_sign_in_detector.rb b/app/lib/suspicious_sign_in_detector.rb index 1af5188c65..74f49aa558 100644 --- a/app/lib/suspicious_sign_in_detector.rb +++ b/app/lib/suspicious_sign_in_detector.rb @@ -19,7 +19,7 @@ class SuspiciousSignInDetector end def previously_seen_ip?(request) - @user.ips.where('ip <<= ?', masked_ip(request)).exists? + @user.ips.exists?(['ip <<= ?', masked_ip(request)]) end def freshly_signed_up?