From f691b4ddd2c4f7187d4ce6ed21f74ab69eae02b8 Mon Sep 17 00:00:00 2001 From: Stephen Hu Date: Mon, 24 Mar 2025 19:08:22 +0800 Subject: [PATCH] Feat: Improve "/convert" API's performance (#6465) ### What problem does this PR solve? for batch requests based on get_by_ids to fetch all files first replace the O(n) IO logic. ### Type of change - [x] Performance Improvement --- api/apps/file2document_app.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/api/apps/file2document_app.py b/api/apps/file2document_app.py index 48a607c0b..d67e5ef0a 100644 --- a/api/apps/file2document_app.py +++ b/api/apps/file2document_app.py @@ -38,8 +38,12 @@ def convert(): file2documents = [] try: + files = FileService.get_by_ids(file_ids) + files_set = set([file.id for file in files]) for file_id in file_ids: - e, file = FileService.get_by_id(file_id) + file = files_set[file_id] + if not file: + return get_data_error_result(message="File not found!") file_ids_list = [file_id] if file.type == FileType.FOLDER.value: file_ids_list = FileService.get_all_innermost_file_ids(file_id, []) @@ -86,6 +90,7 @@ def convert(): "file_id": id, "document_id": doc.id, }) + file2documents.append(file2document.to_json()) return get_json_result(data=file2documents) except Exception as e: