Add fast timeout to group sidebar MR and epic counts
What does this MR do and why?
The group sidebar loads its open counts through the NamespaceSidebar GraphQL type. The issue and work item counts already run under ApplicationRecord.with_fast_read_statement_timeout (4.5 seconds) and return null when it fires. The merge request and epic counts ran under the normal statement timeout, and a timeout failed the whole sidebar query, so no counts were shown.
This MR:
- Adds a
fast_timeout:option (defaultfalse) toGroups::MergeRequestsCountServiceandGroups::EpicsCountService, matchingGroups::OpenIssuesCountServiceandGroups::OpenWorkItemsCountService. Other callers, such asGroup#open_merge_requests_count, are unchanged. - Passes
fast_timeout:fromNamespaceSidebar.openMergeRequestsCount(groups only) andNamespaceSidebar.openEpicsCount, behind thegroup_sidebar_mr_and_epic_counts_fast_timeoutflag (gitlab_com_derisk, disabled by default). - Rescues
ActiveRecord::QueryCanceledfor both counts, logs it withquery: 'group_sidebar_merge_requests_count'orquery: 'group_sidebar_epics_count', and returnsnull, like the issue and work item counts.
Decisions
- The rescue is not behind the flag. With the flag disabled, a count that reaches the normal statement timeout now returns
nullinstead of failing the request. Turning the flag off during rollout therefore still keeps the other sidebar counts working. - No changelog entry. The new timeout is behind a default-off flag. The rescue only changes what happens after a query has already timed out.
- Flag actor is the group's root ancestor, so enabling the flag for a top-level group also covers its subgroups.
root_ancestoris memoized, and both counts share the same actor in a request. - The option is copied into each service to match the two existing services, rather than moved into
Groups::CountService, to keep this change small. - No frontend change. The super sidebar already hides the count pill when a count is
null. - Project namespaces are unchanged. Their merge request count uses
Projects::OpenMergeRequestsCountService, and they have no epic count.
References
- https://gitlab.com/gitlab-org/gitlab/-/work_items/637820
- Refinement plan: https://gitlab.com/gitlab-org/gitlab/-/work_items/637820#note_4191305210
- Feature flag rollout: #639354
Screenshots or screen recordings
Not applicable: backend only. The sidebar looks the same, and it already hides a count that is null.
How to set up and validate locally
-
In the Rails console, enable the feature flag:
Feature.enable(:group_sidebar_mr_and_epic_counts_fast_timeout) -
Visit a group with open merge requests, such as http://127.0.0.1:3000/flightjs. With a Premium or Ultimate license, the group also shows an epic count.
-
In
log/development.log, find theNamespaceSidebarGraphQL request.SET LOCAL statement_timeout = 4500now runs before the merge request and epic count queries. Groups with 1,000 or fewer open items are not cached, so the counts run on every page load. -
Disable the flag with
Feature.disable(:group_sidebar_mr_and_epic_counts_fast_timeout)and reload the page.SET LOCAL statement_timeoutnow runs only before the issue and work item counts.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.