Skip to content

Commit

Permalink
AO3-5053 Remove byline from cache instead of touching all bookmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
irrationalpie7 committed Mar 30, 2024
1 parent 4048cb6 commit ad766d5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/models/bookmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def check_new_external_work

scope :latest, -> { is_public.limit(ArchiveConfig.ITEMS_PER_PAGE).join_work }

scope :for_blurb, -> { includes(:bookmarkable, :pseud, :tags, :collections) }
scope :for_blurb, -> { includes(:bookmarkable, :pseud, :tags, :collections, :user) }

# a complicated dynamic scope here:
# if the user is an Admin, we use the "visible_to_admin" scope
Expand Down
9 changes: 4 additions & 5 deletions app/models/pseud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,10 @@ def check_default_pseud
end

def expire_caches
return unless saved_change_to_name?

bookmarks.touch_all
works.touch_all
series.each(&:expire_byline_cache)
if saved_change_to_name?
works.touch_all
series.each(&:expire_byline_cache)
end
end

def touch_comments
Expand Down
2 changes: 0 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,7 @@ class User < ApplicationRecord

def expire_caches
return unless saved_change_to_login?

series.each(&:expire_byline_cache)
self.bookmarks.touch_all
self.works.each do |work|
work.touch
work.expire_caches
Expand Down
11 changes: 6 additions & 5 deletions app/views/bookmarks/_bookmark_user_module.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<% # expects "bookmark" %>
<div class="<% if is_author_of?(bookmark) %>own <% end %>user module group">
<% blurb_cache_key = (is_author_of?(bookmark) ? "bookmark-owner-blurb-#{bookmark.cache_key}-v2" : "bookmark-blurb-#{bookmark.cache_key}-v2") %>
<!--bookmarker-->
<h5 class="byline heading">
<%= ts('Bookmarked by') %> <%= link_to(bookmark.pseud.byline, user_pseud_bookmarks_path(bookmark.pseud.user, bookmark.pseud)) %>

Check failure on line 5 in app/views/bookmarks/_bookmark_user_module.html.erb

View workflow job for this annotation

GitHub Actions / ERB Lint runner

[] reported by reviewdog 🐶 Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. Raw Output: app/views/bookmarks/_bookmark_user_module.html.erb:5:11: Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
</h5>
<% blurb_cache_key = (is_author_of?(bookmark) ? "bookmark-owner-blurb-#{bookmark.cache_key}-v3" : "bookmark-blurb-#{bookmark.cache_key}-v3") %>
<% cache(blurb_cache_key, skip_digest: true) do %>
<!--bookmarker, time-->
<h5 class="byline heading">
<%= ts('Bookmarked by') %> <%= link_to(bookmark.pseud.byline, user_pseud_bookmarks_path(bookmark.pseud.user, bookmark.pseud)) %>
</h5>
<!--time-->
<p class="datetime"><%= set_format_for_date(bookmark.created_at) %></p>
<% # information added by the bookmark owner %>
Expand Down

0 comments on commit ad766d5

Please sign in to comment.