Skip to content

Implement max limit for assigned issues count

euko requested to merge 381867-max-assigned-issues-count into master

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.

How the counting is done (relevant for database review)

All 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.

  1. Fetch the first issue_assignees record whose user_id is the current user AND meets a certain set of conditions using IssuesFinder (e.g., is open? is accessible? is not authored by banned users?)

  2. Fetch the next issue_assignees record such that its issue_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.

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 Screenshot_2022-12-04_at_16.10.55
After Screenshot_2022-12-04_at_16.10.34

How to set up and validate locally

  1. Enable limit_assigned_issues_count

    Feature.enable(:limit_assigned_issues_count)
  2. 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.

Related to #381867 (closed)

Edited by euko

Merge request reports