This needs to be batched instead of loading all comments and links into memory.  See [scripts/recalc_karma.py](https://github.com/tricycle/lesswrong/blob/1233c31f00dcd1592b65361621c323b4ec64ca31/scripts/recalc_karma.py#L73) for an example.