When using IssuableFinder with a Group we can greatly reduce the amount
of projects operated on (due to not including all public/internal
projects) by simply passing it down to the ProjectsFinder class.
This reduces the timings of the involved queries from roughly 300
ms to roughly 20 ms.
Fixesgitlab-org/gitlab-ce#4071, gitlab-org/gitlab-ce#3707
When grabbing the projects to filter issues by we don't care about the
order they're returned in. By removing the ORDER BY the resulting query
can be quite a bit faster.
When using IssuableFinder/IssuesFinder to find issues for multiple
projects it's more efficient to use a JOIN + a "WHERE project_id IN"
condition opposed to running a sub-query.
This change means that when finding issues without labels we're now
using the following SQL:
SELECT issues.*
FROM issues
JOIN projects ON projects.id = issues.project_id
LEFT JOIN label_links ON label_links.target_type = 'Issue'
AND label_links.target_id = issues.id
WHERE (
projects.id IN (...)
OR projects.visibility_level IN (20, 10)
)
AND issues.state IN ('opened','reopened')
AND label_links.id IS NULL
ORDER BY issues.id DESC;
instead of:
SELECT issues.*
FROM issues
LEFT JOIN label_links ON label_links.target_type = 'Issue'
AND label_links.target_id = issues.id
WHERE issues.project_id IN (
SELECT id
FROM projects
WHERE id IN (...)
OR visibility_level IN (20,10)
)
AND issues.state IN ('opened','reopened')
AND label_links.id IS NULL
ORDER BY issues.id DESC;
The big benefit here is that in the last case PostgreSQL can't properly
use all available indexes. In particular it ends up performing a
sequence scan on the "label_links" table (processing around 290 000
rows). The new query is roughly 2x as fast as the old query.
Since this method's returned data doesn't change between calls on the
same IssuableFinder instance we can just memoize this similar to the
"project" method.
This groups milestones by title for issue views like it has been done for
the milestone dashboard/project overview. Before milestones with the
same title would show up multiple times in the filter dropdown and one could
only filter per project and milestone. Now the milestone filter is based
on the title of the milestone, i.e. all issues marked with the same
milestone title are shown.