Skip to content

Commit

Permalink
Added efficient saving of document chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
annbbbb committed May 6, 2024
1 parent 8b86878 commit 6d3c086
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions api/documents/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 6d3c086

Please sign in to comment.