Implement max limit for assigned issues count
What does this MR do and why?
Resolves #381867 (closed). When a user has many issues assigned, counting all the issues can be a very slow task.
When displaying the assigned issues count in the dashboard, we will only count up to 100
and display 99+
like done with the TODOs count. The idea was UX reviewed in #381867 (comment 1193422760).
As usual, a feature flag limit_assigned_issues_count
will be used to introduce the change.
database review)
How the counting is done (relevant forAll credit goes to @stomlinson
who came up with the idea in #381867 (comment 1175033289).
To count up to 100 assigned open issues, we will iterate through assigned issues using a recursive CTE.
The idea is to iterate through issue_assignees
one by one in the order issue_id
DESC and check if each issue should be counted.
-
Fetch the first
issue_assignees
record whoseuser_id
is the current user AND meets a certain set of conditions usingIssuesFinder
(e.g., is open? is accessible? is not authored by banned users?) -
Fetch the next
issue_assignees
record such that itsissue_id
<previously fetched issue_id
in addition to satisfying the same conditions.
Note 1. The following sample query uses the user id of the customer who reported the performance problem in #381867 (closed).
Note 2. Be careful to not use the admin user when testing this locally. For the non-admin users, the count query should exclude the assigned issues authored by banned users.
-
Query (before): https://postgres.ai/console/gitlab/gitlab-production-tunnel-pg12/sessions/13655/commands/47928
-
Query (after): https://postgres.ai/console/gitlab/gitlab-production-tunnel-pg12/sessions/13655/commands/47930
-
Query (after; using my own user id - 5 issues assigned currently): https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/13655/commands/47931
DB migration outputs
We are replacing an existing index for issue_assignees
to support the new CTE query.
https://gitlab.com/gitlab-org/gitlab/-/jobs/3419426898
Screenshots or screen recordings
Screenshot | |
---|---|
Before | |
After |
How to set up and validate locally
-
Enable
limit_assigned_issues_count
Feature.enable(:limit_assigned_issues_count)
-
Create 100 issues and have them assigned to a user.
To avoid disrupting your workflow, consider creating a new user to be used as the assignee just for this testing.
Here's an example snippet to create 100 assigned open issues:
author = User.first
assignee = User.first
project = Project.find(22)
(1..100).each { |_| Issue.new(title: "haha", author: author, assignees: [assignee], project: project).save! }
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #381867 (closed)