disable all chunks status when disable document (#12149)

This commit is contained in:
Jyong
2024-12-27 17:08:44 +08:00
committed by GitHub
parent 55c327ffcb
commit 5a3fe61f2a
2 changed files with 26 additions and 1 deletions

View File

@@ -1,3 +1,4 @@
import datetime
import logging
import time
@@ -46,6 +47,16 @@ def remove_document_from_index_task(document_id: str):
index_processor.clean(dataset, index_node_ids, with_keywords=True, delete_child_chunks=False)
except Exception:
logging.exception(f"clean dataset {dataset.id} from index failed")
# update segment to disable
db.session.query(DocumentSegment).filter(DocumentSegment.document_id == document.id).update(
{
DocumentSegment.enabled: False,
DocumentSegment.disabled_at: datetime.datetime.now(datetime.UTC).replace(tzinfo=None),
DocumentSegment.disabled_by: document.disabled_by,
DocumentSegment.updated_at: datetime.datetime.now(datetime.UTC).replace(tzinfo=None),
}
)
db.session.commit()
end_at = time.perf_counter()
logging.info(