From 7ea9588520c664f17a02265d8456b2288476cb9b Mon Sep 17 00:00:00 2001 From: luigi <007.lva@gmail.com> Date: Fri, 22 Jan 2021 10:28:15 -0500 Subject: [PATCH] Use Enumerable#filter_map in more places (#15527) --- app/lib/spam_check.rb | 4 ++-- app/presenters/status_relationships_presenter.rb | 2 +- .../activitypub/fetch_featured_collection_service.rb | 7 ++----- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/app/lib/spam_check.rb b/app/lib/spam_check.rb index 68e586d00b..dcb2db9ca9 100644 --- a/app/lib/spam_check.rb +++ b/app/lib/spam_check.rb @@ -186,9 +186,9 @@ class SpamCheck def matching_status_ids if nilsimsa? - other_digests.select { |record| record.start_with?('nilsimsa') && nilsimsa_compare_value(digest, record.split(':')[1]) >= NILSIMSA_COMPARE_THRESHOLD }.filter_map { |record| record.split(':')[2] } + other_digests.filter_map { |record| record.split(':')[2] if record.start_with?('nilsimsa') && nilsimsa_compare_value(digest, record.split(':')[1]) >= NILSIMSA_COMPARE_THRESHOLD } else - other_digests.select { |record| record.start_with?('md5') && record.split(':')[1] == digest }.filter_map { |record| record.split(':')[2] } + other_digests.filter_map { |record| record.split(':')[2] if record.start_with?('md5') && record.split(':')[1] == digest } end end diff --git a/app/presenters/status_relationships_presenter.rb b/app/presenters/status_relationships_presenter.rb index f4849d245b..70fb2ba900 100644 --- a/app/presenters/status_relationships_presenter.rb +++ b/app/presenters/status_relationships_presenter.rb @@ -15,7 +15,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).select { |s| s.account_id == current_account_id && %w(public unlisted).include?(s.visibility) }.map(&:id) + pinnable_status_ids = statuses.map(&:proper).filter_map { |s| s.id if s.account_id == current_account_id && %w(public unlisted).include?(s.visibility) } @reblogs_map = Status.reblogs_map(status_ids, current_account_id).merge(options[:reblogs_map] || {}) @favourites_map = Status.favourites_map(status_ids, current_account_id).merge(options[:favourites_map] || {}) diff --git a/app/services/activitypub/fetch_featured_collection_service.rb b/app/services/activitypub/fetch_featured_collection_service.rb index 82c861f5b8..72352aca6f 100644 --- a/app/services/activitypub/fetch_featured_collection_service.rb +++ b/app/services/activitypub/fetch_featured_collection_service.rb @@ -23,11 +23,8 @@ class ActivityPub::FetchFeaturedCollectionService < BaseService def process_items(items) status_ids = items.map { |item| value_or_id(item) } - .reject { |uri| ActivityPub::TagManager.instance.local_uri?(uri) } - .filter_map { |uri| ActivityPub::FetchRemoteStatusService.new.call(uri) } - .select { |status| status.account_id == @account.id } - .map(&:id) - + .filter_map { |uri| ActivityPub::FetchRemoteStatusService.new.call(uri) unless ActivityPub::TagManager.instance.local_uri?(uri) } + .filter_map { |status| status.id if status.account_id == @account.id } to_remove = [] to_add = status_ids