about summary refs log tree commit diff
path: root/app/services
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2022-11-07 22:35:53 +0100
committerGitHub <noreply@github.com>2022-11-07 22:35:53 +0100
commitbbf74498f57513751f3506e3bbf7a04be4ad3b67 (patch)
treed21003915b94d35099b6b311151e0a9aed459ca9 /app/services
parent3114c826a7a6b2b10bff722c59cca57abe7f819f (diff)
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
Diffstat (limited to 'app/services')
-rw-r--r--app/services/activitypub/fetch_featured_tags_collection_service.rb22
1 files changed, 9 insertions, 13 deletions
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