Feature/timelines aggregations performance

See commits. Fixes [`#2372`](https://www.openproject.org/work_packages/2372).
Replaces https://github.com/opf/openproject/pull/687.