From b0f0f1ff849879124eb0242da38de494e09132c9 Mon Sep 17 00:00:00 2001 From: yangdx Date: Tue, 1 Apr 2025 14:03:45 +0800 Subject: [PATCH] refactor: improve document clearing status management - Use update() for atomic status updates - Improve history messages clearing while preserving list object --- lightrag/api/routers/document_routes.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/lightrag/api/routers/document_routes.py b/lightrag/api/routers/document_routes.py index 1b8ab345..44f54328 100644 --- a/lightrag/api/routers/document_routes.py +++ b/lightrag/api/routers/document_routes.py @@ -998,13 +998,23 @@ def create_document_routes( message="Cannot clear documents while pipeline is busy", ) # Set busy to true - pipeline_status["busy"] = True - pipeline_status["job_name"] = "Clearing Documents" - pipeline_status["latest_message"] = "Starting document clearing process" - if "history_messages" in pipeline_status: - pipeline_status["history_messages"].append( - "Starting document clearing process" - ) + pipeline_status.update( + { + "busy": True, + "job_name": "Clearing Documents", + "job_start": datetime.now().isoformat(), + "docs": 0, + "batchs": 0, + "cur_batch": 0, + "request_pending": False, # Clear any previous request + "latest_message": "Starting document clearing process", + } + ) + # Cleaning history_messages without breaking it as a shared list object + del pipeline_status["history_messages"][:] + pipeline_status["history_messages"].append( + "Starting document clearing process" + ) try: # Use drop method to clear all data