mirror of
https://github.com/discourse/discourse.git
synced 2025-03-05 05:18:55 +08:00
PERF: cache all metadata for 60 seconds
Clients tend to request webmanifests and such very often. Keep the data cached for 60 seconds so it is not requested aggresively.
This commit is contained in:
parent
f69e5a4d7e
commit
7bfbecad7e
@ -5,20 +5,24 @@ class MetadataController < ApplicationController
|
|||||||
skip_before_action :preload_json, :check_xhr, :redirect_to_login_if_required
|
skip_before_action :preload_json, :check_xhr, :redirect_to_login_if_required
|
||||||
|
|
||||||
def manifest
|
def manifest
|
||||||
|
expires_in 1.minutes
|
||||||
render json: default_manifest.to_json, content_type: 'application/manifest+json'
|
render json: default_manifest.to_json, content_type: 'application/manifest+json'
|
||||||
end
|
end
|
||||||
|
|
||||||
def opensearch
|
def opensearch
|
||||||
|
expires_in 1.minutes
|
||||||
render template: "metadata/opensearch.xml"
|
render template: "metadata/opensearch.xml"
|
||||||
end
|
end
|
||||||
|
|
||||||
def app_association_android
|
def app_association_android
|
||||||
raise Discourse::NotFound unless SiteSetting.app_association_android.present?
|
raise Discourse::NotFound unless SiteSetting.app_association_android.present?
|
||||||
|
expires_in 1.minutes
|
||||||
render plain: SiteSetting.app_association_android, content_type: 'application/json'
|
render plain: SiteSetting.app_association_android, content_type: 'application/json'
|
||||||
end
|
end
|
||||||
|
|
||||||
def app_association_ios
|
def app_association_ios
|
||||||
raise Discourse::NotFound unless SiteSetting.app_association_ios.present?
|
raise Discourse::NotFound unless SiteSetting.app_association_ios.present?
|
||||||
|
expires_in 1.minutes
|
||||||
render plain: SiteSetting.app_association_ios, content_type: 'application/json'
|
render plain: SiteSetting.app_association_ios, content_type: 'application/json'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -22,6 +22,8 @@ RSpec.describe MetadataController do
|
|||||||
get "/manifest.webmanifest"
|
get "/manifest.webmanifest"
|
||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
expect(response.media_type).to eq('application/manifest+json')
|
expect(response.media_type).to eq('application/manifest+json')
|
||||||
|
expect(response.headers["Cache-Control"]).to eq('max-age=60, private')
|
||||||
|
|
||||||
manifest = JSON.parse(response.body)
|
manifest = JSON.parse(response.body)
|
||||||
|
|
||||||
expect(manifest["name"]).to eq(title)
|
expect(manifest["name"]).to eq(title)
|
||||||
@ -105,6 +107,8 @@ RSpec.describe MetadataController do
|
|||||||
SiteSetting.favicon = upload
|
SiteSetting.favicon = upload
|
||||||
get "/opensearch.xml"
|
get "/opensearch.xml"
|
||||||
|
|
||||||
|
expect(response.headers["Cache-Control"]).to eq('max-age=60, private')
|
||||||
|
|
||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
expect(response.body).to include(title)
|
expect(response.body).to include(title)
|
||||||
expect(response.body).to include("/search?q={searchTerms}")
|
expect(response.body).to include("/search?q={searchTerms}")
|
||||||
@ -130,6 +134,8 @@ RSpec.describe MetadataController do
|
|||||||
EOF
|
EOF
|
||||||
get "/.well-known/assetlinks.json"
|
get "/.well-known/assetlinks.json"
|
||||||
|
|
||||||
|
expect(response.headers["Cache-Control"]).to eq('max-age=60, private')
|
||||||
|
|
||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
expect(response.body).to include("hash_of_app_certificate")
|
expect(response.body).to include("hash_of_app_certificate")
|
||||||
expect(response.body).to include("com.example.app")
|
expect(response.body).to include("com.example.app")
|
||||||
@ -156,6 +162,7 @@ RSpec.describe MetadataController do
|
|||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
expect(response.body).to include("applinks")
|
expect(response.body).to include("applinks")
|
||||||
expect(response.media_type).to eq('application/json')
|
expect(response.media_type).to eq('application/json')
|
||||||
|
expect(response.headers["Cache-Control"]).to eq('max-age=60, private')
|
||||||
|
|
||||||
get "/apple-app-site-association.json"
|
get "/apple-app-site-association.json"
|
||||||
expect(response.status).to eq(404)
|
expect(response.status).to eq(404)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user