Stream documents in document_archiver via .only() + .iterator()

document_archiver built its document_ids list by materializing every
full Document instance (all fields) just to read has_archive_version.
Restrict the queryset to the two fields actually used and stream it
with .iterator() to avoid loading the whole table into memory at once.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
stumpylog
2026-07-17 11:22:21 -07:00
co-authored by Claude Sonnet 5
parent c753091a44
commit 7d863a553a
@@ -54,8 +54,12 @@ class Command(PaperlessCommand):
else:
documents = Document.objects.all()
documents = documents.only("id", "archive_filename")
document_ids = [
doc.id for doc in documents if overwrite or not doc.has_archive_version
doc.id
for doc in documents.iterator(chunk_size=2000)
if overwrite or not doc.has_archive_version
]
try: