From 00eead9753a409ab3727befe9031623f7db7a8d5 Mon Sep 17 00:00:00 2001 From: Sarken Date: Tue, 17 Oct 2023 03:40:57 -0400 Subject: [PATCH] Ao3-6328 Write tagging count to cache and Redis on tagging create and destroy --- app/models/tag.rb | 3 --- app/models/tagging.rb | 10 ++-------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/app/models/tag.rb b/app/models/tag.rb index c3af4180e39..519a36de453 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -1133,9 +1133,6 @@ def after_update end end - # Ensure tags with count cache can be reindexed. - Rails.cache.delete(taggings_count_cache_key) if tag.saved_change_to_taggings_count_cache? - # Reindex immediately to update the unwrangled bin. if tag.saved_change_to_unwrangleable? tag.reindex_document diff --git a/app/models/tagging.rb b/app/models/tagging.rb index 63a1617c6b0..6c257455070 100644 --- a/app/models/tagging.rb +++ b/app/models/tagging.rb @@ -22,15 +22,9 @@ def self.find_by_tag(taggable, tag) Tagging.find_by(tagger_id: tag.id, taggable_id: taggable.id, tagger_type: 'Tag', taggable_type: taggable.class.name) end - # Most of the time, we don't need the taggings_count_cache stored in the - # database to be perfectly accurate. But because of the way Tag.in_use is - # defined and used, the difference between a value of 0 and a value of 1 is - # important. So we make sure to poke the taggings_count cache every time we - # create or destroy a tagging. If it's a large tag, it'll fall back on the - # cached value. If it's a small tag, it'll recompute -- and make sure that it - # handles the transition from 0 uses to 1 use properly. def update_taggings_count - tagger.update_tag_cache unless tagger.blank? || tagger.destroyed? + return if tagger.blank? || tagger.destroyed? + tagger.taggings_count = tagger.taggings.count end def update_search