mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-06-29 23:41:12 +08:00
Fix session deletion leaking chat-upload blobs (#14969)
### What problem does this PR solve? This fixes a bug where files uploaded in chat were left in storage after the session was deleted. It now removes those chat-uploaded blobs during session deletion. fixes #14965 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
@@ -47,6 +47,7 @@ from api.utils.api_utils import (
|
||||
)
|
||||
from api.utils.tenant_utils import ensure_tenant_model_id_for_params
|
||||
from common.constants import LLMType, RetCode, StatusEnum
|
||||
from common import settings
|
||||
from common.misc_utils import get_uuid, thread_pool_exec
|
||||
from rag.prompts.generator import chunks_format
|
||||
from rag.prompts.template import load_prompt
|
||||
@@ -794,6 +795,17 @@ async def delete_sessions(chat_id):
|
||||
if not ConversationService.query(id=sid, dialog_id=chat_id):
|
||||
errors.append(f"The chat doesn't own the session {sid}")
|
||||
continue
|
||||
ok, conv = ConversationService.get_by_id(sid)
|
||||
if ok:
|
||||
for msg in conv.message or []:
|
||||
for file in msg.get("files") or []:
|
||||
file_id = file.get("id")
|
||||
if not file_id:
|
||||
continue
|
||||
try:
|
||||
settings.STORAGE_IMPL.rm(f"{current_user.id}-downloads", file_id)
|
||||
except Exception:
|
||||
logging.warning("Failed to delete chat upload blob %s/%s", current_user.id, file_id)
|
||||
ConversationService.delete_by_id(sid)
|
||||
success_count += 1
|
||||
all_errors = errors + duplicate_messages
|
||||
|
||||
Reference in New Issue
Block a user