You only need to call `generate_tasks()` once. I think should get reordered to something like this:

```
if run_tasks:
    # Any time we're doing a refresh, we're making sure that
    # the index is ready to be queried. Given that, it's
    # almost always the case that we want to run all the
    # generated tasks, then refresh all the write indexes.
    generate_tasks()

for index in es_utils.all_write_indexes():
    get_es().refresh(index)
```