Fix several caching issues when viewing card permas

This commit is contained in:
Jorge Manrubia
2025-09-18 10:58:09 +02:00
parent d3ebf4c879
commit 690734d8ab
9 changed files with 32 additions and 13 deletions
+3 -3
View File
@@ -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
-4
View File
@@ -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
+1 -1
View File
@@ -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
+23
View File
@@ -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
+1 -1
View File
@@ -1,4 +1,4 @@
<% cache card do %>
<% cache card.cache_invalidation_parts.for_perma do %>
<section id="<%= dom_id(card, :card_container) %>"
class="card-perma" style="--card-color: <%= card.color %>;">
<%= render "cards/container/engagement", card: card %>
+1 -1
View File
@@ -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 %>
<div class="flex flex-column flex-item-grow max-inline-size">
<header class="card__header">
@@ -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 %>
<div class="flex gap">
<div class="flex flex-column flex-item-grow">
@@ -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? %>
<div class="full-width">
@@ -4,7 +4,7 @@
</h2>
<% 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? %>
<div class="full-width">