diff --git a/api/documents/controllers.py b/api/documents/controllers.py index 1744230..d7ded63 100644 --- a/api/documents/controllers.py +++ b/api/documents/controllers.py @@ -16,11 +16,9 @@ def create_document_controller(payload: DocumentIn) -> tuple[HTTPStatus, Documen document.full_clean() document.save() - chunks = split_document_into_chunks(document, 100) - for chunk_data in chunks: - chunk = Chunk(**chunk_data) - chunk.full_clean() - chunk.save() + chunks = split_document_into_chunks(document, 100) + chunk_instances = [Chunk(**chunk_data) for chunk_data in chunks] + Chunk.objects.bulk_create(chunk_instances) return HTTPStatus.CREATED, document