gitlab-org--gitlab-foss/app
Yorick Peterse d29347220c
Refactor ProjectsFinder#init_collection
This changes ProjectsFinder#init_collection so it no longer relies on a
UNION. For example, to get starred projects of a user we used to run:

    SELECT projects.*
    FROM projects
    WHERE projects.pending_delete = 'f'
    AND (
        projects.id IN (
            SELECT projects.id
            FROM projects
            INNER JOIN users_star_projects
                ON users_star_projects.project_id = projects.id
            INNER JOIN project_authorizations
                ON projects.id = project_authorizations.project_id
            WHERE projects.pending_delete = 'f'
            AND project_authorizations.user_id = 1
            AND users_star_projects.user_id = 1

            UNION

            SELECT projects.id
            FROM projects
            INNER JOIN users_star_projects
                ON users_star_projects.project_id = projects.id
            WHERE projects.visibility_level IN (20, 10)
            AND users_star_projects.user_id = 1
        )
    )
    ORDER BY projects.id DESC;

With these changes the above query is turned into the following instead:

    SELECT projects.*
    FROM projects
    INNER JOIN users_star_projects
        ON users_star_projects.project_id = projects.id
    WHERE projects.pending_delete = 'f'
    AND (
        EXISTS (
            SELECT 1
            FROM project_authorizations
            WHERE project_authorizations.user_id = 1
            AND (project_id = projects.id)
        )
        OR projects.visibility_level IN (20,10)
    )
    AND users_star_projects.user_id = 1
    ORDER BY projects.id DESC;

This query in turn produces a better execution plan and takes less time,
though the difference is only a few milliseconds (this however depends
on the amount of data involved and additional conditions that may be
added).
2017-06-16 13:49:09 +02:00
..
assets Merge branch 'translation/9.3/french' into 'master' 2017-06-16 11:35:14 +00:00
controllers Merge branch 'help-landing-page-customizations' into 'master' 2017-06-14 17:16:50 +00:00
finders Refactor ProjectsFinder#init_collection 2017-06-16 13:49:09 +02:00
helpers Merge branch 'feature/unify-email-layouts' into 'master' 2017-06-15 20:15:31 +00:00
mailers use common devise layout and use heading style 2017-06-13 22:36:45 +02:00
models Deserialise existing custom notification settings 2017-06-15 15:15:13 +01:00
policies Allow to access pipelines even if they are disabled, but only present jobs and commit statuses without giving ability to access them 2017-06-13 09:52:48 +02:00
presenters Display issue state in issue links section of merge request widget 2017-06-09 10:21:56 +02:00
serializers Expose correct path to group 2017-06-16 08:54:20 +00:00
services Merge branch 'backport-ee-cache-invalidation-to-ce' into 'master' 2017-06-16 09:01:43 +00:00
uploaders Fix filename method of GitlabUploader to return always real filename 2017-06-13 00:37:12 +02:00
validators Rename Gitlab::Git::EncodingHelper to Gitlab::EncodingHelper 2017-06-01 21:21:14 +00:00
views Update ruby metrics endpoint text to be clearer 2017-06-15 22:00:47 +00:00
workers Add the ability to perform background migrations 2017-06-12 13:24:04 +02:00