Improve performance of the `/hierarchy` endpoint.