Commit 934e065d authored by Sean McGivern's avatar Sean McGivern

Speed up Open list when there are assignee lists

When there is an assignee list and the board can show a lot of issues,
the Open list can be very slow. This was because the query was
essentially repeated inside a NOT IN to exclude issues that are assigned
to someone from one of the assignee lists.

Instead, we can simplify the inner query to be a more direct one:

    NOT EXISTS (
      SELECT 1
      FROM issue_assignees
      WHERE user_id IN ($assignee_list_users)
        AND issue_id = issues.id
    )

Which also performs much better, as well as being simpler to understand.
parent 9eadb163
......@@ -60,8 +60,12 @@ module EE
def without_assignees_from_lists(issues)
return issues if all_assignee_lists.empty?
issues
.where.not(id: issues.joins(:assignees).where(users: { id: all_assignee_lists.select(:user_id) }))
matching_assignee = ::IssueAssignee
.where(user_id: all_assignee_lists.reorder(nil).select(:user_id))
.where("issue_id = issues.id")
.select(1)
issues.where('NOT EXISTS (?)', matching_assignee)
end
# rubocop: enable CodeReuse/ActiveRecord
......
---
title: Fix timeout loading Open list when board contains assignee lists
merge_request:
author:
type: performance
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment