Don't fill up memory when exporting document sets.

[finishes #71065558]

Ideally we'd have tests for this, but I don't know how to write them.