i think you should use the `iter_docs` function in from `dimagi.utils.couch.database` and a generator (`yield` statement) to avoid memory blow ups