mirror of
https://github.com/langgenius/dify.git
synced 2026-04-29 06:58:05 +08:00
[autofix.ci] apply automated fixes
This commit is contained in:
@ -333,7 +333,7 @@ def validate_and_get_api_token(scope: str | None = None):
|
||||
def _query_token_from_db(auth_token: str, scope: str | None) -> ApiToken:
|
||||
"""
|
||||
Query API token from database, update last_used_at, and cache the result.
|
||||
|
||||
|
||||
Raises Unauthorized if token is invalid.
|
||||
"""
|
||||
with Session(db.engine, expire_on_commit=False) as session:
|
||||
@ -354,7 +354,7 @@ def _query_token_from_db(auth_token: str, scope: str | None) -> ApiToken:
|
||||
def _fetch_token_with_single_flight(auth_token: str, scope: str | None) -> ApiToken:
|
||||
"""
|
||||
Fetch token from DB with single-flight pattern using Redis lock.
|
||||
|
||||
|
||||
Ensures only one concurrent request queries the database for the same token.
|
||||
Falls back to direct query if lock acquisition fails.
|
||||
"""
|
||||
|
||||
@ -81,7 +81,7 @@ class ApiTokenCache:
|
||||
# If it's already a Pydantic model, use model_dump_json directly
|
||||
if isinstance(api_token, CachedApiToken):
|
||||
return api_token.model_dump_json().encode("utf-8")
|
||||
|
||||
|
||||
# Otherwise, convert from SQLAlchemy model to CachedApiToken first
|
||||
cached = CachedApiToken(
|
||||
id=str(api_token.id),
|
||||
|
||||
Reference in New Issue
Block a user