Skip to content

Revert to use merge requests count for group view

What does this MR do?

Related to #334039 (closed)

Revert the line in app/views/groups/merge_requests.html.haml that counts MRs and determine if we should render the empty_states template.

In an attempt to improve performance, in this previous MR we changed this template from using the helper method group_merge_requests_count (that performs an expensive COUNT query) to using @merge_requests&.size.

This was a mistake because while group_merge_requests_count(state: 'all') will return the count for all MRs (in any state and ignoring any filters), @merge_requests.size will only return the number of open MRs (affected by filters). As a result, we would be rendering the empty_states template (without the search bar) incorrectly.

This MR changes the template to use the method #issuables_count_for_state for calculating the total count of MRs.

Even though this method also uses an expensive COUNT query to calculate the result, it caches it in Gitlab::SafeRequestStore so it will be called once per request. For the empty_states template this method is already being called once so we know we are not introducing new queries.

Note: This proposed solution #334039 (comment 608268170) is a good idea, performance-wise, but #cached_issuables_count only considers open issuables at the moment.

Screenshots (strongly suggested)

Before - with no Mrs After - with no MRs
Screen_Shot_2021-07-09_at_12.32.34 Screen_Shot_2021-07-09_at_12.34.27
Before - with no open Mrs After - with no open MRs
Screen_Shot_2021-07-09_at_12.36.03 Screen_Shot_2021-07-09_at_12.36.35

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Edited by Eugenia Grieff

Merge request reports