Remove cacheable concern, inline cache helper
This commit is contained in:
@@ -14,7 +14,7 @@ class CardsController < ApplicationController
|
||||
end
|
||||
|
||||
def show
|
||||
fresh_when etag: @card.cache_invalidation_parts.for_perma
|
||||
fresh_when etag: [ @card, @card.collection.columns ]
|
||||
end
|
||||
|
||||
def edit
|
||||
|
||||
@@ -46,4 +46,8 @@ module CardsHelper
|
||||
icon_tag("trash") + tag.span("Remove background image", class: "for-screen-reader")
|
||||
end
|
||||
end
|
||||
|
||||
def card_preview_cache_parts(card)
|
||||
[ card, card.collection.entropy_configuration, card.collection.publication, card.collection.name, card.column ]
|
||||
end
|
||||
end
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
class Card < ApplicationRecord
|
||||
include Assignable, Attachments, Cacheable, Closeable, Colored, Entropic, Eventable,
|
||||
Golden, Mentions, Multistep, Pinnable, Postponable, Promptable, Readable, Searchable,
|
||||
Stallable, Statuses, Taggable, Triageable, Watchable
|
||||
include Assignable, Attachments, Closeable, Colored, Entropic, Eventable,
|
||||
Golden, Mentions, Multistep, Pinnable, Postponable, Promptable, Readable,
|
||||
Searchable, Stallable, Statuses, Taggable, Triageable, Watchable
|
||||
|
||||
belongs_to :collection, touch: true
|
||||
belongs_to :creator, class_name: "User", default: -> { Current.user }
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
module Card::Cacheable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def cache_key
|
||||
[ super, collection.name ].compact.join("/")
|
||||
end
|
||||
|
||||
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
|
||||
[ card, card.collection.columns ]
|
||||
end
|
||||
|
||||
def for_preview
|
||||
[ card, card.collection.entropy_configuration, card.collection.publication, card.column ]
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,4 +1,4 @@
|
||||
<% cache card.cache_invalidation_parts.for_perma do %>
|
||||
<% cache [ card, card.collection.columns ] do %>
|
||||
<section id="<%= dom_id(card, :card_container) %>" class="card-perma" style="--card-color: <%= card.color %>;">
|
||||
<%= render "cards/container/status", card: card %>
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
<%= render partial: "cards/display/preview", collection: column.cards, as: :card, locals: { draggable: draggable }, cached: ->(card) { card.cache_invalidation_parts.for_preview } %>
|
||||
<%= render partial: "cards/display/preview", collection: column.cards, as: :card, locals: { draggable: draggable }, cached: ->(card) { card_preview_cache_parts(card) } %>
|
||||
@@ -1,4 +1,4 @@
|
||||
<% cache card.cache_invalidation_parts.for_preview do %>
|
||||
<% cache card_preview_cache_parts(card) do %>
|
||||
<%= card_article_tag card, class: "card" do %>
|
||||
<div class="flex flex-column flex-item-grow max-inline-size">
|
||||
<header class="card__header">
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
<%= turbo_frame_tag :cards_container do %>
|
||||
<section class="cards cards--grid">
|
||||
<%= with_automatic_pagination :cards_paginated_container, @page do %>
|
||||
<%= render partial: "cards/display/preview", collection: @page.records, as: :card, locals: { draggable: true }, cached: ->(card) { card.cache_invalidation_parts.for_preview } %>
|
||||
<%= render partial: "cards/display/preview", collection: @page.records, as: :card, locals: { draggable: true }, cached: ->(card) { card_preview_cache_parts(card) } %>
|
||||
<% end %>
|
||||
</section>
|
||||
<% end %>
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
<div class="cards__list">
|
||||
<%= render partial: "cards/display/preview", collection: cards, as: :card, locals: { draggable: draggable }, cached: ->(card) { card.cache_invalidation_parts.for_preview } %>
|
||||
<%= render partial: "cards/display/preview", collection: cards, as: :card, locals: { draggable: draggable }, cached: ->(card) { card_preview_cache_parts(card) } %>
|
||||
</div>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<section class="cards cards--grid">
|
||||
<%= with_automatic_pagination :filtered_cards_paginated_container, page do %>
|
||||
<%= render partial: "cards/display/preview", collection: page.records, as: :card, locals: { draggable: true }, cached: ->(card) { card.cache_invalidation_parts.for_preview } %>
|
||||
<%= render partial: "cards/display/preview", collection: page.records, as: :card, locals: { draggable: true }, cached: ->(card) { card_preview_cache_parts(card) } %>
|
||||
<% end %>
|
||||
</section>
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
<div class="cards__list">
|
||||
<%= render partial: "cards/display/public_preview", collection: cards, as: :card, cached: ->(card) { card.cache_invalidation_parts.for_preview } %>
|
||||
<%= render partial: "cards/display/public_preview", collection: cards, as: :card, cached: ->(card) { card_preview_cache_parts(card) } %>
|
||||
</div>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
</h2>
|
||||
|
||||
<% if page.used? %>
|
||||
<%= render partial: "cards/display/public_preview", collection: page.records, as: :card, cached: ->(card) { card.cache_invalidation_parts.for_preview } %>
|
||||
<%= render partial: "cards/display/public_preview", collection: page.records, as: :card, cached: ->(card) { card_preview_cache_parts(card) } %>
|
||||
|
||||
<% unless page.last? %>
|
||||
<div class="full-width">
|
||||
|
||||
@@ -104,17 +104,6 @@ class CardTest < ActiveSupport::TestCase
|
||||
assert_equal [ card, cards(:logo), cards(:text) ].sort, Card.mentioning("haggis").sort
|
||||
end
|
||||
|
||||
test "cache key includes the collection name" do
|
||||
card = cards(:logo)
|
||||
cache_v1_key = card.cache_key
|
||||
|
||||
card.collection.touch
|
||||
assert_equal cache_v1_key, card.reload.cache_key, "general collection touching should not affect the card's cache key"
|
||||
|
||||
card.collection.update! name: "Good ideas"
|
||||
assert_not_equal cache_v1_key, card.reload.cache_key, "changing the name of the collection should invalidate the cache"
|
||||
end
|
||||
|
||||
test "cache key includes the tenant name" do
|
||||
card = cards(:logo)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user