From f50a880d6b746f2d7aa3290379f807952d8bcc7b Mon Sep 17 00:00:00 2001 From: Kevin McConnell Date: Wed, 12 Mar 2025 09:05:50 +0000 Subject: [PATCH] Avoid double render in Avatars#show After sending the conditional 304 response, we were still attempting to render the response, which is unnecessary. --- app/controllers/users/avatars_controller.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/controllers/users/avatars_controller.rb b/app/controllers/users/avatars_controller.rb index 29b4c5996..f700a6825 100644 --- a/app/controllers/users/avatars_controller.rb +++ b/app/controllers/users/avatars_controller.rb @@ -4,12 +4,8 @@ class Users::AvatarsController < ApplicationController before_action :set_user def show - fresh_when @user, cache_control: { max_age: 30.minutes, stale_while_revalidate: 1.week } - - if @user.avatar.attached? - send_blob_stream @user.avatar - else - render_initials + if stale? @user, cache_control: { max_age: 30.minutes, stale_while_revalidate: 1.week } + render_avatar_or_initials end end @@ -23,6 +19,14 @@ class Users::AvatarsController < ApplicationController @user = Current.account.users.find(params[:user_id]) end + def render_avatar_or_initials + if @user.avatar.attached? + send_blob_stream @user.avatar + else + render_initials + end + end + def render_initials render formats: :svg end