Remove remaining N+1 queries in merge requests API with emojis and labels
When serializing to JSON via Grape::Entity, a collection of MergeRequests would have the following methods called:
- label_names
- downvotes
- upvotes
Each of these methods invokes an individual query on the merge request, causing 3N queries per merge request.
For label names, we preload the required labels and just retrieve the titles.
For upvotes and downvotes, we can reuse the IssuableMetadata
logic used to speed up merge request and issue indexes to gather all the required metadata in one query.
Closes #34159 (closed)