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
This commit is contained in:
Stephen Hu 2025-03-24 19:08:22 +08:00 committed by GitHub
parent 3c57a9986c
commit f691b4ddd2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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: