I am facing the task of optimizing the gluing of documents into 1 pdf/zip.
At the moment I only have single-threaded implementations, which work insanely long on a large number of files.
Writing to the archive:
for folder, file_list in folders.items():
for file_obj, new_name in file_list:
zip_file.writestr(
validate_folder(str(folder)) + validate_name(file_obj.name, new_name),
file_obj.open().read(),
)
Writing to pdf:
merger = PdfFileMerger()
For file in files:
merger.append(copy(file), import_bookmarks=False)
c = ContentFile(b'')
merger.write(c)
I have a suggestion to try doing all this in threads, but maybe a more reliable and faster option?