Skip to content

Draft: Simplify query produced by "for_projects_and_groups" scope [RUN ALL RSPEC] [RUN AS-IF-FOSS]

euko requested to merge refactor-timebox-scope-for-projects-and-groups into master

What does this MR do?

Refactors "for_projects_and_groups" scope to simplify resulting queries for the scope.

  • when only one of projects or groups arguments is specified, we can avoid using union.

This MR should not affect any feature or its performance.

Sample query without the change in this MR:

SELECT
    "milestones".*
FROM ((
        SELECT
            "milestones".*
        FROM
            "milestones"
        WHERE
            1 = 0)
    UNION ALL (
        SELECT
            "milestones".*
        FROM
            "milestones"
        WHERE
            "milestones"."group_id" IN (
                SELECT
                    "namespaces"."id"
                FROM
                    "namespaces"
                WHERE
                    "namespaces"."id" IN (9970, 10510295)))) milestones
WHERE ("milestones"."state" IN ('active'))
ORDER BY
    (
        CASE WHEN due_date IS NULL THEN
            1
        WHEN due_date >= CURRENT_DATE THEN
            0
        ELSE
            2
        END) ASC,
"milestones"."due_date" ASC,
"milestones"."id" DESC
LIMIT 20;

Sample query with the change in this MR:

SELECT
    "milestones".*
FROM ((
        SELECT "milestones".* FROM "milestones"
        WHERE
            "milestones"."group_id" IN (
                SELECT
                    "namespaces"."id"
                FROM
                    "namespaces"
                WHERE
                    "namespaces"."id" IN (9970, 10510295)))) milestones
WHERE ("milestones"."state" IN ('active'))
ORDER BY
    (
        CASE WHEN due_date IS NULL THEN
            1
        WHEN due_date >= CURRENT_DATE THEN
            0
        ELSE
            2
        END) ASC,
    "milestones"."due_date" ASC,
    "milestones"."id" DESC
LIMIT 20

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

Does this MR contain changes to processing or storing of credentials or tokens, authorization and authentication methods or other items described in the security review guidelines? If not, then delete this Security section.

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by euko

Merge request reports

Loading