diff --git a/app/controllers/cards_controller.rb b/app/controllers/cards_controller.rb index 1bdd201c0..d14a87c88 100644 --- a/app/controllers/cards_controller.rb +++ b/app/controllers/cards_controller.rb @@ -1,7 +1,7 @@ require "ostruct" class CardsController < ApplicationController - include Collections::ColumnsScoped + include CardsHelper, Collections::ColumnsScoped before_action :set_collection, only: %i[ create ] before_action :set_card, only: %i[ show edit update destroy ] @@ -17,7 +17,7 @@ class CardsController < ApplicationController @closed = page_and_filter_for_closed_cards @cache_key = [ @considering, @on_deck, @doing, @closed ].collect { it.page.records }.including([ Workflow.all, @user_filtering ]) - fresh_when etag: @cache_key + fresh_when etag: [ @cache_key, @user_filtering ] end def create @@ -26,7 +26,7 @@ class CardsController < ApplicationController end def show - fresh_when @card + fresh_when etag: @card.cache_invalidation_parts.for_perma end def edit diff --git a/app/helpers/cards_helper.rb b/app/helpers/cards_helper.rb index cdf5c5d7b..0fba06f5f 100644 --- a/app/helpers/cards_helper.rb +++ b/app/helpers/cards_helper.rb @@ -65,8 +65,4 @@ module CardsHelper title << "assigned to #{card.assignees.map(&:name).to_sentence}" if card.assignees.any? title.join(" ") end - - def cacheable_preview_parts_for(card, *options) - [ card, card.workflow, card.collection.entropy_configuration, card.collection.publication, *options ] - end end diff --git a/app/models/card.rb b/app/models/card.rb index 00214fa5d..fe41c5d9b 100644 --- a/app/models/card.rb +++ b/app/models/card.rb @@ -1,5 +1,5 @@ class Card < ApplicationRecord - include Assignable, Attachments, Closeable, Colored, Engageable, Entropic, Eventable, + include Assignable, Attachments, Cacheable, Closeable, Colored, Engageable, Entropic, Eventable, Golden, Mentions, Multistep, Pinnable, Promptable, Readable, Searchable, Staged, Stallable, Statuses, Taggable, Watchable diff --git a/app/models/card/cacheable.rb b/app/models/card/cacheable.rb new file mode 100644 index 000000000..2456b15b2 --- /dev/null +++ b/app/models/card/cacheable.rb @@ -0,0 +1,23 @@ +module Card::Cacheable + extend ActiveSupport::Concern + + def cache_invalidation_parts + @cache_invalidation_parts ||= InvalidationParts.new(self) + end + + class InvalidationParts + attr_reader :card + + def initialize(card) + @card = card + end + + def for_perma(*other) + [ card, Workflow.all, User.all, Tag.all, *other ] + end + + def for_preview(*other) + [ card, card.workflow, card.collection.entropy_configuration, card.collection.publication, *other ] + end + end +end diff --git a/app/views/cards/_container.html.erb b/app/views/cards/_container.html.erb index 09eb83d11..f067781b1 100644 --- a/app/views/cards/_container.html.erb +++ b/app/views/cards/_container.html.erb @@ -1,4 +1,4 @@ -<% cache card do %> +<% cache card.cache_invalidation_parts.for_perma do %>
<%= render "cards/container/engagement", card: card %> diff --git a/app/views/cards/display/_preview.html.erb b/app/views/cards/display/_preview.html.erb index 9fda1c484..b0e4254ad 100644 --- a/app/views/cards/display/_preview.html.erb +++ b/app/views/cards/display/_preview.html.erb @@ -1,6 +1,6 @@ <% draggable = local_assigns.fetch(:draggable, false) && card.published? %> -<% cache cacheable_preview_parts_for(card, draggable) do %> +<% cache card.cache_invalidation_parts.for_preview(draggable) do %> <%= card_article_tag card, class: "card", draggable: draggable, data: { id: card.id, drag_and_drop_target: "item" } do %>
diff --git a/app/views/cards/display/_public_preview.html.erb b/app/views/cards/display/_public_preview.html.erb index e0f7e945a..95ccc0740 100644 --- a/app/views/cards/display/_public_preview.html.erb +++ b/app/views/cards/display/_public_preview.html.erb @@ -1,4 +1,4 @@ -<% cache cacheable_preview_parts_for(card) do %> +<% cache card.cache_invalidation_parts.for_preview do %> <%= card_article_tag card, class: "card" do %>
diff --git a/app/views/cards/index/engagement/_doing.html.erb b/app/views/cards/index/engagement/_doing.html.erb index 7d69e9322..9dded775d 100644 --- a/app/views/cards/index/engagement/_doing.html.erb +++ b/app/views/cards/index/engagement/_doing.html.erb @@ -13,7 +13,7 @@ <% end %> <% if page.used? %> - <%= render partial: "cards/display/preview", collection: page.records, as: :card, locals: { draggable: true }, cached: ->(card) { cacheable_preview_parts_for(card) } %> + <%= render partial: "cards/display/preview", collection: page.records, as: :card, locals: { draggable: true }, cached: ->(card) { card.cache_invalidation_parts.for_preview } %> <% unless page.last? %>
diff --git a/app/views/public/collections/show/_doing.html.erb b/app/views/public/collections/show/_doing.html.erb index d072bc614..386ce6104 100644 --- a/app/views/public/collections/show/_doing.html.erb +++ b/app/views/public/collections/show/_doing.html.erb @@ -4,7 +4,7 @@ <% if page.used? %> - <%= render partial: "cards/display/public_preview", collection: page.records, as: :card, cached: ->(card) { cacheable_preview_parts_for(card) } %> + <%= render partial: "cards/display/public_preview", collection: page.records, as: :card, cached: ->(card) { card.cache_invalidation_parts.for_preview } %> <% unless page.last? %>