Slow COUNT(*) query for open issues in group page sidebar
Summary
Every group page displays a sidebar with a count for open issues. This query is quite expensive for groups with a large number of issues.
By visiting a group page with the performance bar enabled we can see that the first query is SELECT COUNT(*) FROM "issues..."
and the load time being ~900ms.
The query for counting open issues is performed in GroupsHelper
and called from the sidebar partial.
Proposal
- We could try to optimise the way we calculate this count values and reduce loading times of all group pages.
For example, when looking at the sidebar for the project level, the count for Issues is calculated using Projects::OpenIssuesCountService
, that caches the total count number. This was introduced here to handle the same problem at the Project level.
Could we extend this functionality to cover the Group level?
- From discussion in #243753 (comment 462806542) we could cache this count only when over a certain limit, and display it rounded to thousands to indicate inaccuracy.
Screenshots
Open issues count | COUNT query | Expected appearance for rounded count |
---|---|---|
Edited by Eugenia Grieff