Fix Performance/TimesMap cop (#24789)

pull/24763/head
Matt Jankowski 2023-05-02 12:07:16 -04:00 committed by GitHub
parent bae694108a
commit 570079f8ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 15 additions and 24 deletions

View File

@ -365,15 +365,6 @@ Performance/StartWith:
Exclude:
- 'app/lib/extractor.rb'
# This cop supports unsafe autocorrection (--autocorrect-all).
Performance/TimesMap:
Exclude:
- 'spec/controllers/api/v1/blocks_controller_spec.rb'
- 'spec/controllers/api/v1/mutes_controller_spec.rb'
- 'spec/lib/feed_manager_spec.rb'
- 'spec/lib/request_pool_spec.rb'
- 'spec/models/account_spec.rb'
# This cop supports unsafe autocorrection (--autocorrect-all).
Performance/UnfreezeString:
Exclude:

View File

@ -13,13 +13,13 @@ RSpec.describe Api::V1::BlocksController, type: :controller do
describe 'GET #index' do
it 'limits according to limit parameter' do
2.times.map { Fabricate(:block, account: user.account) }
Array.new(2) { Fabricate(:block, account: user.account) }
get :index, params: { limit: 1 }
expect(body_as_json.size).to eq 1
end
it 'queries blocks in range according to max_id' do
blocks = 2.times.map { Fabricate(:block, account: user.account) }
blocks = Array.new(2) { Fabricate(:block, account: user.account) }
get :index, params: { max_id: blocks[1] }
@ -28,7 +28,7 @@ RSpec.describe Api::V1::BlocksController, type: :controller do
end
it 'queries blocks in range according to since_id' do
blocks = 2.times.map { Fabricate(:block, account: user.account) }
blocks = Array.new(2) { Fabricate(:block, account: user.account) }
get :index, params: { since_id: blocks[0] }
@ -37,7 +37,7 @@ RSpec.describe Api::V1::BlocksController, type: :controller do
end
it 'sets pagination header for next path' do
blocks = 2.times.map { Fabricate(:block, account: user.account) }
blocks = Array.new(2) { Fabricate(:block, account: user.account) }
get :index, params: { limit: 1, since_id: blocks[0] }
expect(response.headers['Link'].find_link(%w(rel next)).href).to eq api_v1_blocks_url(limit: 1, max_id: blocks[1])
end

View File

@ -13,13 +13,13 @@ RSpec.describe Api::V1::MutesController, type: :controller do
describe 'GET #index' do
it 'limits according to limit parameter' do
2.times.map { Fabricate(:mute, account: user.account) }
Array.new(2) { Fabricate(:mute, account: user.account) }
get :index, params: { limit: 1 }
expect(body_as_json.size).to eq 1
end
it 'queries mutes in range according to max_id' do
mutes = 2.times.map { Fabricate(:mute, account: user.account) }
mutes = Array.new(2) { Fabricate(:mute, account: user.account) }
get :index, params: { max_id: mutes[1] }
@ -28,7 +28,7 @@ RSpec.describe Api::V1::MutesController, type: :controller do
end
it 'queries mutes in range according to since_id' do
mutes = 2.times.map { Fabricate(:mute, account: user.account) }
mutes = Array.new(2) { Fabricate(:mute, account: user.account) }
get :index, params: { since_id: mutes[0] }
@ -37,7 +37,7 @@ RSpec.describe Api::V1::MutesController, type: :controller do
end
it 'sets pagination header for next path' do
mutes = 2.times.map { Fabricate(:mute, account: user.account) }
mutes = Array.new(2) { Fabricate(:mute, account: user.account) }
get :index, params: { limit: 1, since_id: mutes[0] }
expect(response.headers['Link'].find_link(%w(rel next)).href).to eq api_v1_mutes_url(limit: 1, max_id: mutes[1])
end

View File

@ -188,7 +188,7 @@ RSpec.describe FeedManager do
it 'trims timelines if they will have more than FeedManager::MAX_ITEMS' do
account = Fabricate(:account)
status = Fabricate(:status)
members = FeedManager::MAX_ITEMS.times.map { |count| [count, count] }
members = Array.new(FeedManager::MAX_ITEMS) { |count| [count, count] }
redis.zadd("feed:home:#{account.id}", members)
FeedManager.instance.push_to_home(account, status)
@ -233,7 +233,7 @@ RSpec.describe FeedManager do
it 'does not save a new reblog of a recently-reblogged status' do
account = Fabricate(:account)
reblogged = Fabricate(:status)
reblogs = 2.times.map { Fabricate(:status, reblog: reblogged) }
reblogs = Array.new(2) { Fabricate(:status, reblog: reblogged) }
# The first reblog will be accepted
FeedManager.instance.push_to_home(account, reblogs.first)
@ -262,7 +262,7 @@ RSpec.describe FeedManager do
it 'does not save a new reblog of a multiply-reblogged-then-unreblogged status' do
account = Fabricate(:account)
reblogged = Fabricate(:status)
reblogs = 3.times.map { Fabricate(:status, reblog: reblogged) }
reblogs = Array.new(3) { Fabricate(:status, reblog: reblogged) }
# Accept the reblogs
FeedManager.instance.push_to_home(account, reblogs[0])
@ -278,7 +278,7 @@ RSpec.describe FeedManager do
it 'saves a new reblog of a long-ago-reblogged status' do
account = Fabricate(:account)
reblogged = Fabricate(:status)
reblogs = 2.times.map { Fabricate(:status, reblog: reblogged) }
reblogs = Array.new(2) { Fabricate(:status, reblog: reblogged) }
# The first reblog will be accepted
FeedManager.instance.push_to_home(account, reblogs.first)
@ -459,7 +459,7 @@ RSpec.describe FeedManager do
it 'leaves a multiply-reblogged status if another reblog was in feed' do
reblogged = Fabricate(:status)
reblogs = 3.times.map { Fabricate(:status, reblog: reblogged) }
reblogs = Array.new(3) { Fabricate(:status, reblog: reblogged) }
reblogs.each do |reblog|
FeedManager.instance.push_to_home(receiver, reblog)

View File

@ -33,7 +33,7 @@ describe RequestPool do
subject
threads = 20.times.map do |_i|
threads = Array.new(20) do |_i|
Thread.new do
20.times do
subject.with('http://example.com') do |http_client|

View File

@ -902,7 +902,7 @@ RSpec.describe Account, type: :model do
describe 'recent' do
it 'returns a relation of accounts sorted by recent creation' do
matches = 2.times.map { Fabricate(:account) }
matches = Array.new(2) { Fabricate(:account) }
expect(Account.where('id > 0').recent).to match_array(matches)
end
end