Issue stats

This pull request improves the performance of the stats for each project. Now, 90 thousand task_runs are processed in 7 seconds while before it took 108 seconds.

This also reduces the impact on memory, as now it uses PostgreSQL cursors.