Avoid double render in Avatars#show

After sending the conditional 304 response, we were still attempting to
render the response, which is unnecessary.
This commit is contained in:
Kevin McConnell
2025-03-12 09:05:50 +00:00
parent e0fa376d4f
commit f50a880d6b
+10 -6
View File
@@ -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