FEATURE: raise redirect avatar cache to 1 day (#19840)

In "GlobalSetting.redirect_avatar_requests" mode, when the application gets
an avatar request it returns a "redirect" to the S3 CDN.

This shields the application from caching avatars and downloading from S3.
However clients will make 2 requests per avatar. (one to get redirect,
second to get avatar)

A one hour cache on a redirect means there may be an increase in CDN
traffic, given more clients will ask for the redirect every hour.

This may also lead to an increase in origin requests to the application.

To mitigate lets cache the CDN URL for 1 day.

The downside is that any changes to S3 CDN need extra care to allow for
the extra 1 day delay. (leave data around for 1 extra day)
This commit is contained in:
Sam 2023-01-12 12:40:42 +11:00 committed by GitHub
parent 7b63c42304
commit 29ef2cb550
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 2 deletions

View File

@ -192,7 +192,7 @@ class UserAvatarsController < ApplicationController
end
def redirect_s3_avatar(url)
immutable_for 1.hour
immutable_for 1.day
redirect_to url, allow_other_host: true
end

View File

@ -139,7 +139,7 @@ RSpec.describe UserAvatarsController do
expect(response.status).to eq(302)
expect(response.location).to eq("https://s3-cdn.example.com/optimized/path")
expect(response.headers["Cache-Control"]).to eq("max-age=3600, public, immutable")
expect(response.headers["Cache-Control"]).to eq("max-age=86400, public, immutable")
end
it "serves new version for old urls" do