Fix Performance/CollectionLiteralInLoop cop (#24819)

This commit is contained in:
Matt Jankowski 2023-05-03 23:33:55 -04:00 committed by GitHub
parent a1cca1c8b6
commit 2c6c398c60
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 35 additions and 30 deletions

View file

@ -5,6 +5,8 @@ class Admin::AppealFilter
status
).freeze
IGNORED_PARAMS = %w(page).freeze
attr_reader :params
def initialize(params)
@ -15,7 +17,7 @@ class Admin::AppealFilter
scope = Appeal.order(id: :desc)
params.each do |key, value|
next if %w(page).include?(key.to_s)
next if IGNORED_PARAMS.include?(key.to_s)
scope.merge!(scope_for(key, value.to_s.strip)) if value.present?
end

View file

@ -6,6 +6,8 @@ class Admin::StatusFilter
report_id
).freeze
IGNORED_PARAMS = %w(page report_id).freeze
attr_reader :params
def initialize(account, params)
@ -17,7 +19,7 @@ class Admin::StatusFilter
scope = @account.statuses.where(visibility: [:public, :unlisted])
params.each do |key, value|
next if %w(page report_id).include?(key.to_s)
next if IGNORED_PARAMS.include?(key.to_s)
scope.merge!(scope_for(key, value.to_s.strip)) if value.present?
end

View file

@ -169,6 +169,8 @@ class MediaAttachment < ApplicationRecord
original: IMAGE_STYLES[:small].freeze,
}.freeze
DEFAULT_STYLES = [:original].freeze
GLOBAL_CONVERT_OPTIONS = {
all: '-quality 90 +profile "!icc,*" +set modify-date +set create-date',
}.freeze

View file

@ -10,6 +10,8 @@ class RelationshipFilter
location
).freeze
IGNORED_PARAMS = %w(relationship page).freeze
attr_reader :params, :account
def initialize(account, params)
@ -23,7 +25,7 @@ class RelationshipFilter
scope = scope_for('relationship', params['relationship'].to_s.strip)
params.each do |key, value|
next if %w(relationship page).include?(key)
next if IGNORED_PARAMS.include?(key)
scope.merge!(scope_for(key.to_s, value.to_s.strip)) if value.present?
end

View file

@ -6,6 +6,8 @@ class Trends::PreviewCardFilter
locale
).freeze
IGNORED_PARAMS = %w(page).freeze
attr_reader :params
def initialize(params)
@ -16,7 +18,7 @@ class Trends::PreviewCardFilter
scope = initial_scope
params.each do |key, value|
next if %w(page).include?(key.to_s)
next if IGNORED_PARAMS.include?(key.to_s)
scope.merge!(scope_for(key, value.to_s.strip)) if value.present?
end

View file

@ -6,6 +6,8 @@ class Trends::StatusFilter
locale
).freeze
IGNORED_PARAMS = %w(page).freeze
attr_reader :params
def initialize(params)
@ -16,7 +18,7 @@ class Trends::StatusFilter
scope = initial_scope
params.each do |key, value|
next if %w(page).include?(key.to_s)
next if IGNORED_PARAMS.include?(key.to_s)
scope.merge!(scope_for(key, value.to_s.strip)) if value.present?
end

View file

@ -1,6 +1,8 @@
# frozen_string_literal: true
class StatusRelationshipsPresenter
PINNABLE_VISIBILITIES = %w(public unlisted private).freeze
attr_reader :reblogs_map, :favourites_map, :mutes_map, :pins_map,
:bookmarks_map, :filters_map
@ -16,7 +18,7 @@ class StatusRelationshipsPresenter
statuses = statuses.compact
status_ids = statuses.flat_map { |s| [s.id, s.reblog_of_id] }.uniq.compact
conversation_ids = statuses.filter_map(&:conversation_id).uniq
pinnable_status_ids = statuses.map(&:proper).filter_map { |s| s.id if s.account_id == current_account_id && %w(public unlisted private).include?(s.visibility) }
pinnable_status_ids = statuses.map(&:proper).filter_map { |s| s.id if s.account_id == current_account_id && PINNABLE_VISIBILITIES.include?(s.visibility) }
@filters_map = build_filters_map(statuses, current_account_id).merge(options[:filters_map] || {})
@reblogs_map = Status.reblogs_map(status_ids, current_account_id).merge(options[:reblogs_map] || {})

View file

@ -4,6 +4,7 @@ class FetchResourceService < BaseService
include JsonLdHelper
ACCEPT_HEADER = 'application/activity+json, application/ld+json; profile="https://www.w3.org/ns/activitystreams", text/html;q=0.1'
ACTIVITY_STREAM_LINK_TYPES = ['application/activity+json', 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'].freeze
attr_reader :response_code
@ -65,7 +66,7 @@ class FetchResourceService < BaseService
def process_html(response)
page = Nokogiri::HTML(response.body_with_limit)
json_link = page.xpath('//link[@rel="alternate"]').find { |link| ['application/activity+json', 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'].include?(link['type']) }
json_link = page.xpath('//link[@rel="alternate"]').find { |link| ACTIVITY_STREAM_LINK_TYPES.include?(link['type']) }
process(json_link['href'], terminal: true) unless json_link.nil?
end

View file

@ -68,7 +68,7 @@ class SuspendAccountService < BaseService
@account.media_attachments.find_each do |media_attachment|
attachment_names.each do |attachment_name|
attachment = media_attachment.public_send(attachment_name)
styles = [:original] | attachment.styles.keys
styles = MediaAttachment::DEFAULT_STYLES | attachment.styles.keys
next if attachment.blank?

View file

@ -64,7 +64,7 @@ class UnsuspendAccountService < BaseService
@account.media_attachments.find_each do |media_attachment|
attachment_names.each do |attachment_name|
attachment = media_attachment.public_send(attachment_name)
styles = [:original] | attachment.styles.keys
styles = MediaAttachment::DEFAULT_STYLES | attachment.styles.keys
next if attachment.blank?