Skip to content

Commit

Permalink
Ao3-6328 Write tagging count to cache and Redis on tagging create and…
Browse files Browse the repository at this point in the history
… destroy
  • Loading branch information
sarken committed Oct 17, 2023
1 parent 9705a64 commit 00eead9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 11 deletions.
3 changes: 0 additions & 3 deletions app/models/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 2 additions & 8 deletions app/models/tagging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 00eead9

Please sign in to comment.