Skip to content

Commit

Permalink
Fix Rails/WhereExists cop in app/lib (mastodon#28862)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjankowski authored Jan 24, 2024
1 parent 41c2af2 commit 1290fed
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 11 deletions.
4 changes: 0 additions & 4 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions app/lib/activitypub/activity/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def poll_vote!
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

Expand Down Expand Up @@ -406,7 +406,7 @@ def addresses_local_accounts?

return false if local_usernames.empty?

Account.local.where(username: local_usernames).exists?
Account.local.exists?(username: local_usernames)
end

def tombstone_exists?
Expand Down
2 changes: 1 addition & 1 deletion app/lib/delivery_failure_tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def days
end

def available?
!UnavailableDomain.where(domain: @host).exists?
!UnavailableDomain.exists?(domain: @host)
end

def exhausted_deliveries_days
Expand Down
6 changes: 3 additions & 3 deletions app/lib/feed_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,8 @@ def filter_from_mentions?(status, receiver_id)
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
Expand All @@ -434,7 +434,7 @@ def filter_from_list?(status, list)
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
Expand Down
2 changes: 1 addition & 1 deletion app/lib/suspicious_sign_in_detector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def sufficient_security_measures?
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?
Expand Down

0 comments on commit 1290fed

Please sign in to comment.