From bae694108a1cd9a228ae798d6fdfcd4a70a795cf Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 2 May 2023 12:06:43 -0400 Subject: [PATCH] Fix Performance/Count cop (#24793) --- .rubocop_todo.yml | 6 ------ app/lib/importer/accounts_index_importer.rb | 4 ++-- app/lib/importer/tags_index_importer.rb | 4 ++-- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 900bb8201..cac72400f 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -308,12 +308,6 @@ Performance/CollectionLiteralInLoop: - 'config/deploy.rb' - 'lib/mastodon/media_cli.rb' -# This cop supports unsafe autocorrection (--autocorrect-all). -Performance/Count: - Exclude: - - 'app/lib/importer/accounts_index_importer.rb' - - 'app/lib/importer/tags_index_importer.rb' - # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: SafeMultiline. Performance/DeletePrefix: diff --git a/app/lib/importer/accounts_index_importer.rb b/app/lib/importer/accounts_index_importer.rb index 792a31b1b..fd869c396 100644 --- a/app/lib/importer/accounts_index_importer.rb +++ b/app/lib/importer/accounts_index_importer.rb @@ -6,8 +6,8 @@ class Importer::AccountsIndexImporter < Importer::BaseImporter in_work_unit(tmp) do |accounts| bulk = Chewy::Index::Import::BulkBuilder.new(index, to_index: accounts).bulk_body - indexed = bulk.select { |entry| entry[:index] }.size - deleted = bulk.select { |entry| entry[:delete] }.size + indexed = bulk.count { |entry| entry[:index] } + deleted = bulk.count { |entry| entry[:delete] } Chewy::Index::Import::BulkRequest.new(index).perform(bulk) diff --git a/app/lib/importer/tags_index_importer.rb b/app/lib/importer/tags_index_importer.rb index f5bd8f052..77710ed7d 100644 --- a/app/lib/importer/tags_index_importer.rb +++ b/app/lib/importer/tags_index_importer.rb @@ -6,8 +6,8 @@ class Importer::TagsIndexImporter < Importer::BaseImporter in_work_unit(tmp) do |tags| bulk = Chewy::Index::Import::BulkBuilder.new(index, to_index: tags).bulk_body - indexed = bulk.select { |entry| entry[:index] }.size - deleted = bulk.select { |entry| entry[:delete] }.size + indexed = bulk.count { |entry| entry[:index] } + deleted = bulk.count { |entry| entry[:delete] } Chewy::Index::Import::BulkRequest.new(index).perform(bulk)