mirror of https://github.com/zulip/zulip.git
storage: Hash system bots avatar files.
This commit makes sure system bots avatar files are hashed when served as static files. This way, requests for these avatar files will be served with long-lived caching headers by our nginx (see #22275). We don't need to worry about stale caches for these files because they will only be used by system bots. Fixes #31458.
This commit is contained in:
parent
46db52dc96
commit
c9375fb5ee
|
@ -14,6 +14,8 @@ from zerver.lib.url_encoding import append_url_query_string
|
|||
from zerver.models import UserProfile
|
||||
|
||||
SYSTEM_BOTS_AVATAR_FILES = {
|
||||
# This is also used in zerver/lib/storage.py to ensure
|
||||
# these files are hashed when served as static files.
|
||||
settings.WELCOME_BOT: "images/welcome-bot.png",
|
||||
settings.NOTIFICATION_BOT: "images/logo/zulip-icon-square.svg",
|
||||
settings.EMAIL_GATEWAY_BOT: "images/email-gateway-bot.png",
|
||||
|
|
|
@ -10,6 +10,8 @@ from django.core.files.base import File
|
|||
from django.core.files.storage import FileSystemStorage
|
||||
from typing_extensions import override
|
||||
|
||||
from zerver.lib.avatar import SYSTEM_BOTS_AVATAR_FILES
|
||||
|
||||
if settings.DEBUG:
|
||||
from django.contrib.staticfiles.finders import find
|
||||
|
||||
|
@ -38,6 +40,12 @@ class IgnoreBundlesManifestStaticFilesStorage(ManifestStaticFilesStorage):
|
|||
# use a no-op hash function for these already-hashed
|
||||
# assets.
|
||||
return name
|
||||
if name in SYSTEM_BOTS_AVATAR_FILES.values():
|
||||
# For these avatar files, we want to make sure they are
|
||||
# so they can hit our Nginx caching block for static files.
|
||||
# We don't need to worry about stale caches since system bot
|
||||
# avatars rarely change.
|
||||
return super().hashed_name(name, content, filename)
|
||||
if name == "generated/emoji/emoji_api.json":
|
||||
# Unlike most .json files, we do want to hash this file;
|
||||
# its hashed URL is returned as part of the API. See
|
||||
|
|
Loading…
Reference in New Issue