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.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
chore: use zstd for plugin model provider cache (#38382)
非法操作91cc50371ba6
diff --git a/api/core/plugin/plugin_service.py b/api/core/plugin/plugin_service.pyindex a6d83e85dbc..805c52329b3 100644--- a/api/core/plugin/plugin_service.py+++ b/api/core/plugin/plugin_service.py@@ -4,7 +4,7 @@ This module owns plugin daemon management calls that are shared by API servicesand core runtimes. Plugin model provider discovery is cached here, alongsideplugin install, uninstall, and upgrade invalidation, so all cache mutations forplugin-owned provider metadata stay tenant-scoped and in one place.-Provider cache payloads may be stored as prefixed zlib bytes; readers also+Provider cache payloads may be stored as prefixed zstd bytes; readers alsoaccept legacy plain JSON payloads for rolling upgrades and existing Redis keys.The console plugin list also normalizes endpoint setup counters against live@@ -16,12 +16,12 @@ metadata.import loggingimport time-import zlibfrom collections.abc import Iterator, Mapping, Sequencefrom contextlib import contextmanagerfrom mimetypes import guess_typefrom typing import Literal, Protocol+import zstandardfrom pydantic import BaseModel, TypeAdapter, ValidationErrorfrom redis import RedisErrorfrom redis.exceptions import LockError@@ -95,7 +95,7 @@ class PluginService:PLUGIN_MODEL_PROVIDERS_LOCK_TTL = 30PLUGIN_MODEL_PROVIDERS_LOCK_WAIT_TIMEOUT = 2.0PLUGIN_MODEL_PROVIDERS_LOCK_WAIT_INTERVAL = 0.05- PLUGIN_MODEL_PROVIDERS_CACHE_COMPRESSION_PREFIX = b"\x00dify-plugin-model-providers-zlib-v1:"+ PLUGIN_MODEL_PROVIDERS_CACHE_COMPRESSION_PREFIX = b"\x00dify-plugin-model-providers-zstd-v1:"PLUGIN_MODEL_PROVIDERS_CACHE_COMPRESSION_MIN_BYTES = 64 * 1024PLUGIN_INSTALL_TASK_TERMINAL_STATUSES = (PluginInstallTaskStatus.Success, PluginInstallTaskStatus.Failed)# Mirror the detail-panel endpoint query size so list reconciliation and@@ -152,7 +152,7 @@ class PluginService:if len(payload) < cls.PLUGIN_MODEL_PROVIDERS_CACHE_COMPRESSION_MIN_BYTES:return payload- return cls.PLUGIN_MODEL_PROVIDERS_CACHE_COMPRESSION_PREFIX + zlib.compress(payload, level=1)+ return cls.PLUGIN_MODEL_PROVIDERS_CACHE_COMPRESSION_PREFIX + zstandard.compress(payload, level=1)@classmethoddef _decode_plugin_model_providers_cache_payload(cls, payload: bytes | bytearray | str) -> bytes | bytearray | str:@@ -164,8 +164,8 @@ class PluginService:return payloadtry:- return zlib.decompress(payload[len(prefix) :])- except zlib.error as exc:+ return zstandard.decompress(payload[len(prefix) :])+ except zstandard.ZstdError as exc:raise ValueError("Invalid compressed plugin model providers cache payload.") from exc@classmethoddiff --git a/api/pyproject.toml b/api/pyproject.tomlindex 9978dad738f..d3fcb59d694 100644--- a/api/pyproject.toml+++ b/api/pyproject.toml@@ -42,6 +42,7 @@ dependencies = ["opentelemetry-propagator-b3>=1.41.1,<2.0.0","readabilipy==0.3.0","resend>=2.27.0,<3.0.0",+ "zstandard==0.25.0",# Emerging: newer and fast-moving, use compatible pins"fastopenapi[flask]==0.7.0","graphon==0.6.0",diff --git a/api/tests/unit_tests/services/plugin/test_plugin_service.py b/api/tests/unit_tests/services/plugin/test_plugin_service.pyindex 11230b25b40..bd8d84834fb 100644--- a/api/tests/unit_tests/services/plugin/test_plugin_service.py+++ b/api/tests/unit_tests/services/plugin/test_plugin_service.py@@ -1,10 +1,10 @@import datetimeimport uuid-import zlibfrom types import SimpleNamespacefrom unittest.mock import MagicMock, Mock, call, patchimport pytest+import zstandardfrom pydantic import TypeAdapterfrom redis import RedisError@@ -154,7 +154,7 @@ class TestPluginModelProviderCache:prefix = PluginService.PLUGIN_MODEL_PROVIDERS_CACHE_COMPRESSION_PREFIXassert stored_payload.startswith(prefix)assert len(stored_payload) < len(raw_payload)- assert zlib.decompress(stored_payload[len(prefix) :]) == raw_payload+ assert zstandard.decompress(stored_payload[len(prefix) :]) == raw_payloaddef test_fetch_plugin_model_providers_reads_compressed_cached_provider_without_calling_daemon(self) -> None:"""Compressed tenant cache entries are decoded before provider schema validation."""@@ -166,7 +166,7 @@ class TestPluginModelProviderCache:from core.plugin.plugin_service import PluginService- compressed_payload = PluginService.PLUGIN_MODEL_PROVIDERS_CACHE_COMPRESSION_PREFIX + zlib.compress(+ compressed_payload = PluginService.PLUGIN_MODEL_PROVIDERS_CACHE_COMPRESSION_PREFIX + zstandard.compress(cached_payload, level=1)diff --git a/api/uv.lock b/api/uv.lockindex df9effefdf5..6e7e1811064 100644--- a/api/uv.lock+++ b/api/uv.lock@@ -1375,6 +1375,7 @@ dependencies = [{ name = "resend" },{ name = "sendgrid" },{ name = "sseclient-py" },+ { name = "zstandard" },][package.dev-dependencies]@@ -1658,6 +1659,7 @@ requires-dist = [{ name = "resend", specifier = ">=2.27.0,<3.0.0" },{ name = "sendgrid", specifier = ">=6.12.5,<7.0.0" },{ name = "sseclient-py", specifier = ">=1.8.0,<2.0.0" },+ { name = "zstandard", specifier = "==0.25.0" },][package.metadata.requires-dev]