Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions app/models/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,28 @@ def clear_icon
self.icon_comment_text = nil
end

def self.expire_blurb_cache(id)
# Expire both versions of the blurb, whether the user is logged in or not.
%w[logged-in logged-out].each do |logged_in|
cache_key = "collection-blurb-#{logged_in}-#{id}-v5"
ActionController::Base.new.expire_fragment(cache_key)
end
end

def self.expire_profile_cache(id)
ActionController::Base.new.expire_fragment("collection-profile-#{id}")
end

def self.expire_caches(id)
Collection.expire_blurb_cache(id)
Collection.expire_profile_cache(id)
end

# Blurbs use data from Elasticsearch via CollectionDecorator, so we need to refresh the blurb cache on reindex
def self.successful_reindex(ids)
ids.each { |id| Collection.expire_blurb_cache(id) }
end

# Work and bookmark counts for indexing; these come from the database.

def general_works_count
Expand Down
13 changes: 1 addition & 12 deletions app/sweepers/collection_sweeper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,7 @@ def get_collections_from_record(record)
def expire_collection_cache_for(record)
collections = get_collections_from_record(record)
collections.each do |collection|
CollectionSweeper.expire_collection_blurb_and_profile(collection)
Collection.expire_caches(collection.id)
end
end

# Expire the collection blurb and profile
def self.expire_collection_blurb_and_profile(collection)
# Expire both versions of the blurb, whether the user is logged in or not.
%w[logged-in logged-out].each do |logged_in|
cache_key = "collection-blurb-#{logged_in}-#{collection.id}-v5"
ActionController::Base.new.expire_fragment(cache_key)
end

ActionController::Base.new.expire_fragment("collection-profile-#{collection.id}")
end
end
2 changes: 1 addition & 1 deletion app/views/collections/_collection_blurb.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<li class="<% if collection.user_is_owner?(current_user) %>own <% end %>collection picture blurb group" role="article">
<% logged_in = (logged_in_as_admin? || logged_in?) ? "logged-in" : "logged-out" %>
<%# remember to update collection_sweeper if you change this key %>
<%# remember to update Collection.expire_blurb_cache if you change this key %>
<% cache("collection-blurb-#{logged_in}-#{collection.id}-v5", expires_in: ArchiveConfig.MINUTES_UNTIL_COLLECTION_BLURBS_EXPIRE.minutes, skip_digest: true) do %>
<div class="header module group">
<h4 class="heading">
Expand Down
16 changes: 16 additions & 0 deletions features/gift_exchanges/challenge_giftexchange.feature
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ Feature: Gift Exchange Challenge
When I view open challenges
Then I should see "My Gift Exchange"

Scenario: Gift exchange blurb cache is expired when the collection changes
Given I am logged in as "mod1"
And I have created the gift exchange "My Gift Exchange"
When I go to the collections page
Then I should see "My Gift Exchange"
When I am on "My Gift Exchange" collection edit page
And I check "This collection is anonymous"
And I submit
When I follow "Collections"
# Change not visible yet because not reindexed
Then I should not see "Anonymous" within ".blurb"
When all indexing jobs have been run
And I reload the page
# Reindexed and cache busted
Then I should see "Anonymous" within ".blurb"

Scenario: Change timezone for a gift exchange
Given time is frozen at 1/1/2019
And the gift exchange "My Gift Exchange" is ready for signups
Expand Down
Loading