From bbf74498f57513751f3506e3bbf7a04be4ad3b67 Mon Sep 17 00:00:00 2001 From: Claire Date: Mon, 7 Nov 2022 22:35:53 +0100 Subject: Fix validation error in SynchronizeFeaturedTagsCollectionWorker (#20018) * Fix followers count not being updated when migrating follows Fixes #19900 * Fix validation error in SynchronizeFeaturedTagsCollectionWorker Also saves remote user's chosen case for hashtags * Limit remote featured tags before validation --- .../fetch_featured_tags_collection_service.rb | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'app/services') diff --git a/app/services/activitypub/fetch_featured_tags_collection_service.rb b/app/services/activitypub/fetch_featured_tags_collection_service.rb index 555919938..ab047a0f8 100644 --- a/app/services/activitypub/fetch_featured_tags_collection_service.rb +++ b/app/services/activitypub/fetch_featured_tags_collection_service.rb @@ -51,21 +51,17 @@ class ActivityPub::FetchFeaturedTagsCollectionService < BaseService end def process_items(items) - names = items.filter_map { |item| item['type'] == 'Hashtag' && item['name']&.delete_prefix('#') }.map { |name| HashtagNormalizer.new.normalize(name) } - to_remove = [] - to_add = names - - FeaturedTag.where(account: @account).map(&:name).each do |name| - if names.include?(name) - to_add.delete(name) - else - to_remove << name - end - end + names = items.filter_map { |item| item['type'] == 'Hashtag' && item['name']&.delete_prefix('#') }.take(FeaturedTag::LIMIT) + tags = names.index_by { |name| HashtagNormalizer.new.normalize(name) } + normalized_names = tags.keys - FeaturedTag.includes(:tag).where(account: @account, tags: { name: to_remove }).delete_all unless to_remove.empty? + FeaturedTag.includes(:tag).references(:tag).where(account: @account).where.not(tag: { name: normalized_names }).delete_all + + FeaturedTag.includes(:tag).references(:tag).where(account: @account, tag: { name: normalized_names }).each do |featured_tag| + featured_tag.update(name: tags.delete(featured_tag.tag.name)) + end - to_add.each do |name| + tags.each_value do |name| FeaturedTag.create!(account: @account, name: name) end end -- cgit