From 738227951bff4cc7256b38f4111ea80dbceeace1 Mon Sep 17 00:00:00 2001 From: sarken Date: Sun, 20 Oct 2024 19:28:48 -0400 Subject: [PATCH] AO3-6825 Update bookmark blurbs when bookmarker's tags are renamed --- app/helpers/bookmarks_helper.rb | 5 ---- app/models/tag.rb | 15 ++++++++++++ .../bookmarks/_bookmark_blurb_short.html.erb | 8 +++---- .../bookmarks/_bookmark_user_module.html.erb | 3 ++- .../tag_wrangling_admin.feature | 24 +++++++++++++++---- 5 files changed, 41 insertions(+), 14 deletions(-) diff --git a/app/helpers/bookmarks_helper.rb b/app/helpers/bookmarks_helper.rb index a9c09e3b2f4..c16587a105b 100644 --- a/app/helpers/bookmarks_helper.rb +++ b/app/helpers/bookmarks_helper.rb @@ -24,11 +24,6 @@ def get_new_bookmark_path(bookmarkable) end end - # tag_bookmarks_path was behaving badly for tags with slashes - def link_to_tag_bookmarks(tag) - {controller: 'bookmarks', action: 'index', tag_id: tag} - end - def link_to_bookmarkable_bookmarks(bookmarkable, link_text='') if link_text.blank? link_text = number_with_delimiter(Bookmark.count_visible_bookmarks(bookmarkable, current_user)) diff --git a/app/models/tag.rb b/app/models/tag.rb index ebbf35987a9..fa63efd4a94 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -227,6 +227,21 @@ def flush_work_cache end end + # queue_flush_work_cache will update the cached work (bookmarkable) info for + # bookmarks, but we still need to expire the portion of bookmark blurbs that + # contains the bookmarker's tags. + after_update :queue_flush_bookmark_cache + def queue_flush_bookmark_cache + async_after_commit(:flush_bookmark_cache) if saved_change_to_name? + end + + def flush_bookmark_cache + self.bookmarks.each do |bookmark| + ActionController::Base.new.expire_fragment("bookmark-owner-blurb-#{bookmark.cache_key}-v2") + ActionController::Base.new.expire_fragment("bookmark-blurb-#{bookmark.cache_key}-v2") + end + end + before_save :set_last_wrangler def set_last_wrangler unless User.current_user.nil? diff --git a/app/views/bookmarks/_bookmark_blurb_short.html.erb b/app/views/bookmarks/_bookmark_blurb_short.html.erb index dd9ebaa4830..8a4529cf9ed 100755 --- a/app/views/bookmarks/_bookmark_blurb_short.html.erb +++ b/app/views/bookmarks/_bookmark_blurb_short.html.erb @@ -15,14 +15,14 @@
<%= ts("Bookmark Tags:") %>
<% end %> <% unless bookmark.collections.blank? %>
<%= ts("Bookmark Collections:") %>
@@ -36,8 +36,8 @@ <% end %> <% if is_author_of?(bookmark) %> - <%= render :partial => 'bookmarks/bookmark_owner_navigation', :locals => {:bookmark => bookmark} %> + <%= render "bookmark_owner_navigation", bookmark: bookmark %> <% elsif logged_in_as_admin? %> - <%= render :partial => 'admin/admin_options', :locals => {:item => bookmark} %> + <%= render "admin/admin_options", item: bookmark %> <% end %> diff --git a/app/views/bookmarks/_bookmark_user_module.html.erb b/app/views/bookmarks/_bookmark_user_module.html.erb index c77b104ebfb..1be517f4d59 100644 --- a/app/views/bookmarks/_bookmark_user_module.html.erb +++ b/app/views/bookmarks/_bookmark_user_module.html.erb @@ -1,5 +1,6 @@ <% # expects "bookmark" %>
+ <%# If you update the cache key, update flush_bookmark_cache in tag.rb %> <% blurb_cache_key = (is_author_of?(bookmark) ? "bookmark-owner-blurb-#{bookmark.cache_key}-v2" : "bookmark-blurb-#{bookmark.cache_key}-v2") %> <% cache(blurb_cache_key, skip_digest: true) do %> @@ -14,7 +15,7 @@
<%= ts('Bookmarker\'s Tags:') %>
<% end %> diff --git a/features/tags_and_wrangling/tag_wrangling_admin.feature b/features/tags_and_wrangling/tag_wrangling_admin.feature index 5d70da67b07..1d8982c1b34 100644 --- a/features/tags_and_wrangling/tag_wrangling_admin.feature +++ b/features/tags_and_wrangling/tag_wrangling_admin.feature @@ -1,11 +1,18 @@ @users @tag_wrangling @admin Feature: Tag wrangling - Scenario: Admin can rename a tag + Scenario: Admin can rename a tag and it updates works and bookmarks. - Given I am logged in as an admin - And a fandom exists with name: "Amelie", canonical: false - When I edit the tag "Amelie" + Given I am logged in as "audrey" with password "password" + And I post the work "Renoir's Boating Party" + And I bookmark the work "Renoir's Boating Party" with the tags "Amelie" + And I post the work "Luncheon" with fandom "Amelie" + # Visit the relevant pages to make sure the data gets cached. + And I go to my bookmarks page + And I go to my works page + And I go to the work "Luncheon" + When I am logged in as an admin + And I edit the tag "Amelie" And I fill in "Synonym of" with "Amélie" And I press "Save changes" Then I should see "Amélie is considered the same as Amelie by the database" @@ -15,6 +22,15 @@ Feature: Tag wrangling Then I should see "Tag was updated" And I should see "Amélie" And I should not see "Amelie" + When I go to audrey's works page + Then I should not see "Amelie" + And I should see "Amélie" + When I go to the work "Luncheon" + Then I should not see "Amelie" + And I should see "Amélie" + When I go to audrey's bookmarks page + Then I should not see "Amelie" + And I should see "Amélie" Scenario: Admin can rename a tag using Eastern characters