Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

improve: cache tool icons by setting max-age HTTP header and enable gzip compression SVG icons from backend (#2971)

Bowen Liang1f98a4fff382
diff --git a/api/config.py b/api/config.py
index 61ccdfee7b0..d602db5c2c7 100644
--- a/api/config.py
+++ b/api/config.py
@@ -59,7 +59,8 @@ DEFAULTS = {
'CAN_REPLACE_LOGO': 'False',
'ETL_TYPE': 'dify',
'KEYWORD_STORE': 'jieba',
- 'BATCH_UPLOAD_LIMIT': 20
+ 'BATCH_UPLOAD_LIMIT': 20,
+ 'TOOL_ICON_CACHE_MAX_AGE': 3600,
}
@@ -298,6 +299,7 @@ class Config:
self.BATCH_UPLOAD_LIMIT = get_env('BATCH_UPLOAD_LIMIT')
self.API_COMPRESSION_ENABLED = get_bool_env('API_COMPRESSION_ENABLED')
+ self.TOOL_ICON_CACHE_MAX_AGE = get_env('TOOL_ICON_CACHE_MAX_AGE')
class CloudEditionConfig(Config):
diff --git a/api/controllers/console/workspace/tool_providers.py b/api/controllers/console/workspace/tool_providers.py
index 931979c7f36..f9c2bc8d1cd 100644
--- a/api/controllers/console/workspace/tool_providers.py
+++ b/api/controllers/console/workspace/tool_providers.py
@@ -1,6 +1,6 @@
import io
-from flask import send_file
+from flask import current_app, send_file
from flask_login import current_user
from flask_restful import Resource, reqparse
from werkzeug.exceptions import Forbidden
@@ -80,7 +80,8 @@ class ToolBuiltinProviderIconApi(Resource):
@setup_required
def get(self, provider):
icon_bytes, minetype = ToolManageService.get_builtin_tool_provider_icon(provider)
- return send_file(io.BytesIO(icon_bytes), mimetype=minetype)
+ icon_cache_max_age = int(current_app.config.get('TOOL_ICON_CACHE_MAX_AGE'))
+ return send_file(io.BytesIO(icon_bytes), mimetype=minetype, max_age=icon_cache_max_age)
class ToolModelProviderIconApi(Resource):
@setup_required
diff --git a/api/extensions/ext_compress.py b/api/extensions/ext_compress.py
index caa61675fbc..4a349d37b41 100644
--- a/api/extensions/ext_compress.py
+++ b/api/extensions/ext_compress.py
@@ -5,6 +5,12 @@ def init_app(app: Flask):
if app.config.get('API_COMPRESSION_ENABLED', False):
from flask_compress import Compress
+ app.config['COMPRESS_MIMETYPES'] = [
+ 'application/json',
+ 'image/svg+xml',
+ 'text/html',
+ ]
+
compress = Compress()
compress.init_app(app)