Merge pull request #119 from basecamp/add-caching

Add caching
This commit is contained in:
David Heinemeier Hansson
2024-10-20 03:36:08 +02:00
committed by GitHub
8 changed files with 32 additions and 26 deletions
+1
View File
@@ -19,6 +19,7 @@ class BubblesController < ApplicationController
end
def show
fresh_when etag: @bubble
end
def edit
+1 -1
View File
@@ -1,7 +1,7 @@
class Comment < ApplicationRecord
include Searchable
belongs_to :bubble
belongs_to :bubble, touch: true
belongs_to :creator, class_name: "User", default: -> { Current.user }
searchable_by :body, using: :comments_search_index
+1 -1
View File
@@ -4,7 +4,7 @@ class Event < ApplicationRecord
include Assignments
belongs_to :creator, class_name: "User"
belongs_to :bubble
belongs_to :bubble, touch: true
has_one :account, through: :creator
+1
View File
@@ -7,6 +7,7 @@
<hr class="flex-item-grow margin-none" aria-hidden="true">
<%# FIXME: Move this Current.user check to a stimulus controller that just checks for admin? or the like we so we can cache user list %>
<%= button_to account_user_path(user), method: :delete, class: "btn btn--small btn--negative flex-item-no-shrink",
disabled: !Current.user.can_remove?(user),
data: { turbo_confirm: "Are you sure you want to permanently remove this person from the account?" } do %>
+25 -23
View File
@@ -1,26 +1,28 @@
<div class="bubble"
style="view-transition-name: bubble-<%= bubble.id -%>; --bubble-color: <%= bubble.color %>; <%= bubble_rotation(bubble) %> <%= bubble_size(bubble) %>"
data-controller="upload-preview">
<% cache bubble do %>
<div class="bubble"
style="view-transition-name: bubble-<%= bubble.id -%>; --bubble-color: <%= bubble.color %>; <%= bubble_rotation(bubble) %> <%= bubble_size(bubble) %>"
data-controller="upload-preview">
<h1 class="bubble__title">
<%= turbo_frame_tag bubble, :edit do %>
<%= link_to bubble.title, edit_bucket_bubble_path(bubble.bucket, bubble), class: "txt-undecorated" %>
<h1 class="bubble__title">
<%= turbo_frame_tag bubble, :edit do %>
<%= link_to bubble.title, edit_bucket_bubble_path(bubble.bucket, bubble), class: "txt-undecorated" %>
<% end %>
</h1>
<svg class="bubble__svg" viewBox="0 0 990 990" xmlns="http://www.w3.org/2000/svg">
<path d="m0 0h990v990h-990z" fill="none" stroke="none" />
<path d="m391.65 879.47c-110.52-15.95-212.21-91.86-255.92-191.23-66.78-143.65-41.62-347.61 48.08-481.17 368.33-516.3 1252.97 520.2 451.03 660.78-44.07 8.84-88.98 13.49-133.01 15.68-36.69 2-73.37 1.91-109.99-4.03z"/>
</svg>
<%= link_to bucket_bubble_path(bubble.bucket, bubble), class: "bubble__link" do %>
<span class="for-screen-reader"><%= bubble.title %></span>
<% end %>
</h1>
<svg class="bubble__svg" viewBox="0 0 990 990" xmlns="http://www.w3.org/2000/svg">
<path d="m0 0h990v990h-990z" fill="none" stroke="none" />
<path d="m391.65 879.47c-110.52-15.95-212.21-91.86-255.92-191.23-66.78-143.65-41.62-347.61 48.08-481.17 368.33-516.3 1252.97 520.2 451.03 660.78-44.07 8.84-88.98 13.49-133.01 15.68-36.69 2-73.37 1.91-109.99-4.03z"/>
</svg>
<%= link_to bucket_bubble_path(bubble.bucket, bubble), class: "bubble__link" do %>
<span class="for-screen-reader"><%= bubble.title %></span>
<% end %>
<%= render "bubbles/assignments", bubble: bubble %>
<%= render "bubbles/boosts", bubble: bubble %>
<%= render "bubbles/color", bubble: bubble %>
<%= render "bubbles/date", bubble: bubble %>
<%= render "bubbles/image", bubble: bubble %>
<%= render "bubbles/tags", bubble: bubble %>
</div>
<%= render "bubbles/assignments", bubble: bubble %>
<%= render "bubbles/boosts", bubble: bubble %>
<%= render "bubbles/color", bubble: bubble %>
<%= render "bubbles/date", bubble: bubble %>
<%= render "bubbles/image", bubble: bubble %>
<%= render "bubbles/tags", bubble: bubble %>
</div>
<% end %>
+1 -1
View File
@@ -20,7 +20,7 @@
<section class="windshield flex-inline flex-wrap gap justify-center align-end" style="view-transition-name: windshield_<%= @bucket.id %>">
<% if @bubbles.any? %>
<%= render partial: "bubbles/bubble", collection: @bubbles.limit(10) %>
<%= render partial: "bubbles/bubble", collection: @bubbles.limit(10), cached: true %>
<% else %>
<p><strong>Nothing here.</strong></p>
<% end %>
+1
View File
@@ -24,6 +24,7 @@
<small class="flex align-center gap flex-item-no-shrink">
<% bubble.tags.each do |tag| %>
<%# FIXME: This is not going to work, this partial must be cacheable, so it can't mutate a changeable view filter live. Need a JS solution. %>
<%= link_to "##{tag.title}", bucket_bubbles_path(bubble.bucket, view_filter_params.merge(tag_ids: tag.id)), style: "color: #{bubble.color}" %>
<% end %>
+1
View File
@@ -1,3 +1,4 @@
<%# FIXME: Can't use a Current.user reference in a partial that must be cached. Needs to convert to use Stimulus controller pulling from a meta current-id %>
<%= tag.div id: dom_id(comment), class: [ "comment flex align-start full-width", { "comment--mine": Current.user == comment.creator } ] do %>
<figure class="comment__avatar flex-item-no-shrink">
<%= avatar_tag comment.creator, loading: :lazy %>