Skip to content

Reduce number of queries for finding iterations

Alexandru Croitor requested to merge iterations-finder-reduce-queries into master

What does this MR do?

Base on the fact that a user that has access to any group or project in a branch of the hierarchy can read all iterations in that branch and current usages of fetching iterations, this MR tweaks the permission checks to check the read permission on a single node in the hierarchy tree which should be enough to know if user can read ancestor iterations. That help reduce queries for fetching iterations.

Tested scenario:

  • Hierarchy: 3 groups and leaf node has a project, IDs (parent -> leaf): Group(107) -> Group(108) -> Group(110) -> Project(29)
  • User: the user is member only in the Project.
  • Iterations are spread across groups s follows: Group(107): 4, Group(108): 5, Group(110): 4

Results:

  • before change
    • fetching iterations from Project(29) level with include_ancestors: true: 30(30)
      • building params: 6
      • fetching iterations: 24
      • repeated fetch with sam params: 24
    • fetching iterations from Group(110) level with include_ancestors: true: 24(22)
      • building params: 5
      • fetching iterations: 19
      • repeated fetch with sam params: 17
  • after change
    • fetching iterations from Project(29) level with include_ancestors: true: 10(5)
      • building params: 2
      • fetching iterations: 8
      • repeated fetch with sam params: 3
    • fetching iterations from Group(110) level with include_ancestors: true: 9(4)
      • building params: 2
      • fetching iterations: 7
      • repeated fetch with sam params: 3

Logs:

  • before change
    • fetching iterations from Project(29) level with `include_ancestors
      
          [10] pry(main)> params = IterationsFinder.params_for_parent(Project.find(29), include_ancestors: true)
          Project Load (0.6ms)  SELECT "projects".* FROM "projects" WHERE "projects"."id" = 29 LIMIT 1 /*application:console,line:(pry):10:in `__pry__'*/
            Namespace Load (0.5ms)  SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."id" = 110 LIMIT 1 /*application:console,line:/ee/app/finders/iterations_finder.rb:29:in `params_for_parent'*/
            Group Load (0.8ms)  WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "id" FROM "base_and_ancestors" AS "namespaces" /*application:console,line:/Users/acroitor/.asdf/installs/ruby/2.7.2/lib/ruby/2.7.0/pp.rb:163:in `block in pp'*/
            Route Load (0.2ms)  SELECT "routes".* FROM "routes" WHERE "routes"."source_id" = 110 AND "routes"."source_type" = 'Namespace' LIMIT 1 /*application:console,line:/app/models/concerns/routable.rb:118:in `full_path'*/
            Route Load (0.2ms)  SELECT "routes".* FROM "routes" WHERE "routes"."source_id" = 108 AND "routes"."source_type" = 'Namespace' LIMIT 1 /*application:console,line:/app/models/concerns/routable.rb:118:in `full_path'*/
            Route Load (0.2ms)  SELECT "routes".* FROM "routes" WHERE "routes"."source_id" = 107 AND "routes"."source_type" = 'Namespace' LIMIT 1 /*application:console,line:/app/models/concerns/routable.rb:118:in `full_path'*/
          => {:group_ids=>[#, #, #], :project_ids=>29}
            [11] pry(main)> iterations = IterationsFinder.new(user, params).execute
          Project Load (1.2ms)  SELECT "projects".* FROM "projects" WHERE "projects"."id" IN (SELECT "projects"."id" FROM "projects" WHERE "projects"."id" = 29) /*application:console,line:/app/models/project.rb:718:in `block in projects_user_can'*/
            ProjectFeature Load (1.0ms)  SELECT "project_features".* FROM "project_features" WHERE "project_features"."project_id" = 29 LIMIT 1 /*application:console,line:/app/policies/project_policy.rb:722:in `access_allowed_to?'*/
            Group Load (0.6ms)  SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110 AND "namespaces"."type" = 'Group' LIMIT 1 /*application:console,line:/ee/app/policies/ee/project_policy.rb:307:in `block (2 levels) in '*/
            Namespace Load (0.6ms)  SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."id" = 108 LIMIT 1 /*application:console,line:/app/models/namespaces/traversal/recursive.rb:9:in `root_ancestor'*/
            Group Load (1.2ms)  WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "namespaces".* FROM "base_and_ancestors" AS "namespaces" WHERE "namespaces"."parent_id" IS NULL LIMIT 1 /*application:console,line:/app/models/namespaces/traversal/recursive.rb:13:in `block in root_ancestor'*/
            SamlProvider Load (0.2ms)  SELECT "saml_providers".* FROM "saml_providers" WHERE "saml_providers"."group_id" = 107 LIMIT 1 /*application:console,line:/ee/lib/gitlab/auth/group_saml/sso_enforcer.rb:35:in `group_access_restricted?'*/
             (0.4ms)  SELECT MAX("project_authorizations"."access_level") AS maximum_access_level, "project_authorizations"."user_id" AS project_authorizations_user_id FROM "project_authorizations" WHERE "project_authorizations"."project_id" = 29 AND "project_authorizations"."user_id" = 92 GROUP BY "project_authorizations"."user_id" /*application:console,line:/app/models/project_team.rb:173:in `block in max_member_access_for_user_ids'*/
            Group Load (2.1ms)  WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" IN (WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "id" FROM "base_and_ancestors" AS "namespaces"))
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT namespaces.id, namespaces.parent_id, gitlab_subscriptions.hosted_plan_id FROM "base_and_ancestors" AS "namespaces" LEFT OUTER JOIN gitlab_subscriptions ON gitlab_subscriptions.namespace_id=namespaces.id /*application:console,line:/ee/lib/gitlab/group_plans_preloader.rb:20:in `each_with_object'*/
            Plan Load (0.2ms)  SELECT "plans".* FROM "plans" WHERE 1=0 /*application:console,line:/ee/lib/gitlab/group_plans_preloader.rb:46:in `each_with_object'*/
            Group Load (1.3ms)  SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" IN (WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "id" FROM "base_and_ancestors" AS "namespaces") /*application:console,line:/ee/lib/gitlab/group_plans_preloader.rb:51:in `preload'*/
            SamlProvider Load (0.3ms)  SELECT "saml_providers".* FROM "saml_providers" WHERE "saml_providers"."group_id" = 107 LIMIT 1 /*application:console,line:/ee/lib/gitlab/auth/group_saml/sso_enforcer.rb:35:in `group_access_restricted?'*/
            GroupMember Load (1.1ms)  SELECT "members".* FROM ((SELECT "members".* FROM "members" LEFT OUTER JOIN "users" ON "members"."user_id" = "users"."id" WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "users"."state" = 'active' AND "members"."requested_at" IS NULL AND "members"."invite_token" IS NULL AND (members.access_level > 5) AND (members.access_level > 5) AND "members"."source_id" = 107)
          UNION
          (WITH "group_group_links_cte" AS MATERIALIZED (SELECT "group_group_links".* FROM "group_group_links" WHERE "group_group_links"."shared_group_id" = 107) SELECT "members"."id", LEAST("group_group_links"."group_access", "members"."access_level") AS access_level, "members"."source_id", "members"."source_type", "members"."user_id", "members"."notification_level", "members"."type", "members"."created_at", "members"."updated_at", "members"."created_by_id", "members"."invite_email", "members"."invite_token", "members"."invite_accepted_at", "members"."requested_at", "members"."expires_at", "members"."ldap", "members"."override" FROM "members", "group_group_links_cte" AS "group_group_links" WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "members"."requested_at" IS NULL AND "members"."source_id" = "group_group_links"."shared_with_group_id" AND "members"."source_type" = 'Namespace' AND (members.access_level > 5))) members WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "members"."user_id" = 92 ORDER BY "members"."access_level" DESC LIMIT 1 /*application:console,line:/app/models/group.rb:586:in `max_member_access'*/
            Project Exists? (1.8ms)  SELECT 1 AS one FROM "projects" WHERE "projects"."namespace_id" IN (WITH RECURSIVE "base_and_descendants" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 107)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_descendants" WHERE "namespaces"."type" = 'Group' AND "namespaces"."parent_id" = "base_and_descendants"."id")) SELECT "id" FROM "base_and_descendants" AS "namespaces") AND (EXISTS (SELECT 1 FROM "project_authorizations" WHERE "project_authorizations"."user_id" = 92 AND (project_authorizations.project_id = projects.id)) OR projects.visibility_level IN (10,20)) LIMIT 1 /*application:console,line:/app/policies/group_policy.rb:27:in `block in '*/
            Namespace Load (0.5ms)  SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."id" = 107 LIMIT 1 /*application:console,line:/app/models/namespaces/traversal/recursive.rb:9:in `root_ancestor'*/
            Group Load (1.2ms)  WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 108)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "namespaces".* FROM "base_and_ancestors" AS "namespaces" WHERE "namespaces"."parent_id" IS NULL LIMIT 1 /*application:console,line:/app/models/namespaces/traversal/recursive.rb:13:in `block in root_ancestor'*/
            SamlProvider Load (0.3ms)  SELECT "saml_providers".* FROM "saml_providers" WHERE "saml_providers"."group_id" = 107 LIMIT 1 /*application:console,line:/ee/lib/gitlab/auth/group_saml/sso_enforcer.rb:35:in `group_access_restricted?'*/
            GroupMember Load (3.2ms)  SELECT "members".* FROM ((SELECT "members".* FROM "members" LEFT OUTER JOIN "users" ON "members"."user_id" = "users"."id" WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "users"."state" = 'active' AND "members"."requested_at" IS NULL AND "members"."invite_token" IS NULL AND (members.access_level > 5) AND (members.access_level > 5) AND "members"."source_id" IN (WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 108)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "id" FROM "base_and_ancestors" AS "namespaces"))
          UNION
          (WITH "group_group_links_cte" AS MATERIALIZED (SELECT "group_group_links".* FROM "group_group_links" WHERE "group_group_links"."shared_group_id" IN (WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 108)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "id" FROM "base_and_ancestors" AS "namespaces")) SELECT "members"."id", LEAST("group_group_links"."group_access", "members"."access_level") AS access_level, "members"."source_id", "members"."source_type", "members"."user_id", "members"."notification_level", "members"."type", "members"."created_at", "members"."updated_at", "members"."created_by_id", "members"."invite_email", "members"."invite_token", "members"."invite_accepted_at", "members"."requested_at", "members"."expires_at", "members"."ldap", "members"."override" FROM "members", "group_group_links_cte" AS "group_group_links" WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "members"."requested_at" IS NULL AND "members"."source_id" = "group_group_links"."shared_with_group_id" AND "members"."source_type" = 'Namespace' AND (members.access_level > 5))) members WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "members"."user_id" = 92 ORDER BY "members"."access_level" DESC LIMIT 1 /*application:console,line:/app/models/group.rb:586:in `max_member_access'*/
            Project Exists? (1.4ms)  SELECT 1 AS one FROM "projects" WHERE "projects"."namespace_id" IN (WITH RECURSIVE "base_and_descendants" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 108)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_descendants" WHERE "namespaces"."type" = 'Group' AND "namespaces"."parent_id" = "base_and_descendants"."id")) SELECT "id" FROM "base_and_descendants" AS "namespaces") AND (EXISTS (SELECT 1 FROM "project_authorizations" WHERE "project_authorizations"."user_id" = 92 AND (project_authorizations.project_id = projects.id)) OR projects.visibility_level IN (10,20)) LIMIT 1 /*application:console,line:/app/policies/group_policy.rb:27:in `block in '*/
            Namespace Load (0.4ms)  SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."id" = 108 LIMIT 1 /*application:console,line:/app/models/namespaces/traversal/recursive.rb:9:in `root_ancestor'*/
            Group Load (0.9ms)  WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "namespaces".* FROM "base_and_ancestors" AS "namespaces" WHERE "namespaces"."parent_id" IS NULL LIMIT 1 /*application:console,line:/app/models/namespaces/traversal/recursive.rb:13:in `block in root_ancestor'*/
            SamlProvider Load (0.2ms)  SELECT "saml_providers".* FROM "saml_providers" WHERE "saml_providers"."group_id" = 107 LIMIT 1 /*application:console,line:/ee/lib/gitlab/auth/group_saml/sso_enforcer.rb:35:in `group_access_restricted?'*/
            GroupMember Load (3.7ms)  SELECT "members".* FROM ((SELECT "members".* FROM "members" LEFT OUTER JOIN "users" ON "members"."user_id" = "users"."id" WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "users"."state" = 'active' AND "members"."requested_at" IS NULL AND "members"."invite_token" IS NULL AND (members.access_level > 5) AND (members.access_level > 5) AND "members"."source_id" IN (WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "id" FROM "base_and_ancestors" AS "namespaces"))
          UNION
          (WITH "group_group_links_cte" AS MATERIALIZED (SELECT "group_group_links".* FROM "group_group_links" WHERE "group_group_links"."shared_group_id" IN (WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "id" FROM "base_and_ancestors" AS "namespaces")) SELECT "members"."id", LEAST("group_group_links"."group_access", "members"."access_level") AS access_level, "members"."source_id", "members"."source_type", "members"."user_id", "members"."notification_level", "members"."type", "members"."created_at", "members"."updated_at", "members"."created_by_id", "members"."invite_email", "members"."invite_token", "members"."invite_accepted_at", "members"."requested_at", "members"."expires_at", "members"."ldap", "members"."override" FROM "members", "group_group_links_cte" AS "group_group_links" WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "members"."requested_at" IS NULL AND "members"."source_id" = "group_group_links"."shared_with_group_id" AND "members"."source_type" = 'Namespace' AND (members.access_level > 5))) members WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "members"."user_id" = 92 ORDER BY "members"."access_level" DESC LIMIT 1 /*application:console,line:/app/models/group.rb:586:in `max_member_access'*/
            Project Exists? (1.7ms)  SELECT 1 AS one FROM "projects" WHERE "projects"."namespace_id" IN (WITH RECURSIVE "base_and_descendants" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_descendants" WHERE "namespaces"."type" = 'Group' AND "namespaces"."parent_id" = "base_and_descendants"."id")) SELECT "id" FROM "base_and_descendants" AS "namespaces") AND (EXISTS (SELECT 1 FROM "project_authorizations" WHERE "project_authorizations"."user_id" = 92 AND (project_authorizations.project_id = projects.id)) OR projects.visibility_level IN (10,20)) LIMIT 1 /*application:console,line:/app/policies/group_policy.rb:27:in `block in '*/
            Iteration Load (0.6ms)  SELECT "sprints".* FROM ((SELECT "sprints".* FROM "sprints" WHERE "sprints"."project_id" = 29)
          UNION ALL
          (SELECT "sprints".* FROM "sprints" WHERE "sprints"."group_id" IN (107, 108, 110))) sprints ORDER BY due_date ASC NULLS LAST, "sprints"."title" ASC /*application:console,line:/Users/acroitor/.asdf/installs/ruby/2.7.2/lib/ruby/2.7.0/pp.rb:163:in `block in pp'*/
          => [#,
           #,
           #,
           #,
           #,
           #,
           #,
           #,
           #,
           #,
           #,
           #,
           #]
          [12] pry(main)> iterations = IterationsFinder.new(user, params).execute
            Project Load (1.0ms)  SELECT "projects".* FROM "projects" WHERE "projects"."id" IN (SELECT "projects"."id" FROM "projects" WHERE "projects"."id" = 29) /*application:console,line:/app/models/project.rb:718:in `block in projects_user_can'*/
            ProjectFeature Load (0.4ms)  SELECT "project_features".* FROM "project_features" WHERE "project_features"."project_id" = 29 LIMIT 1 /*application:console,line:/app/policies/project_policy.rb:722:in `access_allowed_to?'*/
            Group Load (0.6ms)  SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110 AND "namespaces"."type" = 'Group' LIMIT 1 /*application:console,line:/ee/app/policies/ee/project_policy.rb:307:in `block (2 levels) in '*/
            Namespace Load (0.4ms)  SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."id" = 108 LIMIT 1 /*application:console,line:/app/models/namespaces/traversal/recursive.rb:9:in `root_ancestor'*/
            Group Load (1.4ms)  WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "namespaces".* FROM "base_and_ancestors" AS "namespaces" WHERE "namespaces"."parent_id" IS NULL LIMIT 1 /*application:console,line:/app/models/namespaces/traversal/recursive.rb:13:in `block in root_ancestor'*/
            SamlProvider Load (0.2ms)  SELECT "saml_providers".* FROM "saml_providers" WHERE "saml_providers"."group_id" = 107 LIMIT 1 /*application:console,line:/ee/lib/gitlab/auth/group_saml/sso_enforcer.rb:35:in `group_access_restricted?'*/
             (0.2ms)  SELECT MAX("project_authorizations"."access_level") AS maximum_access_level, "project_authorizations"."user_id" AS project_authorizations_user_id FROM "project_authorizations" WHERE "project_authorizations"."project_id" = 29 AND "project_authorizations"."user_id" = 92 GROUP BY "project_authorizations"."user_id" /*application:console,line:/app/models/project_team.rb:173:in `block in max_member_access_for_user_ids'*/
            Group Load (1.1ms)  WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" IN (107, 108, 110))
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT namespaces.id, namespaces.parent_id, gitlab_subscriptions.hosted_plan_id FROM "base_and_ancestors" AS "namespaces" LEFT OUTER JOIN gitlab_subscriptions ON gitlab_subscriptions.namespace_id=namespaces.id /*application:console,line:/ee/lib/gitlab/group_plans_preloader.rb:20:in `each_with_object'*/
            Plan Load (0.2ms)  SELECT "plans".* FROM "plans" WHERE 1=0 /*application:console,line:/ee/lib/gitlab/group_plans_preloader.rb:46:in `each_with_object'*/
            Group Load (0.4ms)  SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" IN (107, 108, 110) /*application:console,line:/ee/lib/gitlab/group_plans_preloader.rb:51:in `preload'*/
            SamlProvider Load (0.3ms)  SELECT "saml_providers".* FROM "saml_providers" WHERE "saml_providers"."group_id" = 107 LIMIT 1 /*application:console,line:/ee/lib/gitlab/auth/group_saml/sso_enforcer.rb:35:in `group_access_restricted?'*/
            GroupMember Load (1.3ms)  SELECT "members".* FROM ((SELECT "members".* FROM "members" LEFT OUTER JOIN "users" ON "members"."user_id" = "users"."id" WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "users"."state" = 'active' AND "members"."requested_at" IS NULL AND "members"."invite_token" IS NULL AND (members.access_level > 5) AND (members.access_level > 5) AND "members"."source_id" = 107)
          UNION
          (WITH "group_group_links_cte" AS MATERIALIZED (SELECT "group_group_links".* FROM "group_group_links" WHERE "group_group_links"."shared_group_id" = 107) SELECT "members"."id", LEAST("group_group_links"."group_access", "members"."access_level") AS access_level, "members"."source_id", "members"."source_type", "members"."user_id", "members"."notification_level", "members"."type", "members"."created_at", "members"."updated_at", "members"."created_by_id", "members"."invite_email", "members"."invite_token", "members"."invite_accepted_at", "members"."requested_at", "members"."expires_at", "members"."ldap", "members"."override" FROM "members", "group_group_links_cte" AS "group_group_links" WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "members"."requested_at" IS NULL AND "members"."source_id" = "group_group_links"."shared_with_group_id" AND "members"."source_type" = 'Namespace' AND (members.access_level > 5))) members WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "members"."user_id" = 92 ORDER BY "members"."access_level" DESC LIMIT 1 /*application:console,line:/app/models/group.rb:586:in `max_member_access'*/
            Project Exists? (1.6ms)  SELECT 1 AS one FROM "projects" WHERE "projects"."namespace_id" IN (WITH RECURSIVE "base_and_descendants" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 107)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_descendants" WHERE "namespaces"."type" = 'Group' AND "namespaces"."parent_id" = "base_and_descendants"."id")) SELECT "id" FROM "base_and_descendants" AS "namespaces") AND (EXISTS (SELECT 1 FROM "project_authorizations" WHERE "project_authorizations"."user_id" = 92 AND (project_authorizations.project_id = projects.id)) OR projects.visibility_level IN (10,20)) LIMIT 1 /*application:console,line:/app/policies/group_policy.rb:27:in `block in '*/
            Namespace Load (0.5ms)  SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."id" = 107 LIMIT 1 /*application:console,line:/app/models/namespaces/traversal/recursive.rb:9:in `root_ancestor'*/
            Group Load (1.5ms)  WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 108)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "namespaces".* FROM "base_and_ancestors" AS "namespaces" WHERE "namespaces"."parent_id" IS NULL LIMIT 1 /*application:console,line:/app/models/namespaces/traversal/recursive.rb:13:in `block in root_ancestor'*/
            SamlProvider Load (0.3ms)  SELECT "saml_providers".* FROM "saml_providers" WHERE "saml_providers"."group_id" = 107 LIMIT 1 /*application:console,line:/ee/lib/gitlab/auth/group_saml/sso_enforcer.rb:35:in `group_access_restricted?'*/
            GroupMember Load (3.0ms)  SELECT "members".* FROM ((SELECT "members".* FROM "members" LEFT OUTER JOIN "users" ON "members"."user_id" = "users"."id" WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "users"."state" = 'active' AND "members"."requested_at" IS NULL AND "members"."invite_token" IS NULL AND (members.access_level > 5) AND (members.access_level > 5) AND "members"."source_id" IN (WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 108)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "id" FROM "base_and_ancestors" AS "namespaces"))
          UNION
          (WITH "group_group_links_cte" AS MATERIALIZED (SELECT "group_group_links".* FROM "group_group_links" WHERE "group_group_links"."shared_group_id" IN (WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 108)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "id" FROM "base_and_ancestors" AS "namespaces")) SELECT "members"."id", LEAST("group_group_links"."group_access", "members"."access_level") AS access_level, "members"."source_id", "members"."source_type", "members"."user_id", "members"."notification_level", "members"."type", "members"."created_at", "members"."updated_at", "members"."created_by_id", "members"."invite_email", "members"."invite_token", "members"."invite_accepted_at", "members"."requested_at", "members"."expires_at", "members"."ldap", "members"."override" FROM "members", "group_group_links_cte" AS "group_group_links" WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "members"."requested_at" IS NULL AND "members"."source_id" = "group_group_links"."shared_with_group_id" AND "members"."source_type" = 'Namespace' AND (members.access_level > 5))) members WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "members"."user_id" = 92 ORDER BY "members"."access_level" DESC LIMIT 1 /*application:console,line:/app/models/group.rb:586:in `max_member_access'*/
            Project Exists? (1.5ms)  SELECT 1 AS one FROM "projects" WHERE "projects"."namespace_id" IN (WITH RECURSIVE "base_and_descendants" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 108)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_descendants" WHERE "namespaces"."type" = 'Group' AND "namespaces"."parent_id" = "base_and_descendants"."id")) SELECT "id" FROM "base_and_descendants" AS "namespaces") AND (EXISTS (SELECT 1 FROM "project_authorizations" WHERE "project_authorizations"."user_id" = 92 AND (project_authorizations.project_id = projects.id)) OR projects.visibility_level IN (10,20)) LIMIT 1 /*application:console,line:/app/policies/group_policy.rb:27:in `block in '*/
            Namespace Load (0.5ms)  SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."id" = 108 LIMIT 1 /*application:console,line:/app/models/namespaces/traversal/recursive.rb:9:in `root_ancestor'*/
            Group Load (1.0ms)  WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "namespaces".* FROM "base_and_ancestors" AS "namespaces" WHERE "namespaces"."parent_id" IS NULL LIMIT 1 /*application:console,line:/app/models/namespaces/traversal/recursive.rb:13:in `block in root_ancestor'*/
            SamlProvider Load (0.3ms)  SELECT "saml_providers".* FROM "saml_providers" WHERE "saml_providers"."group_id" = 107 LIMIT 1 /*application:console,line:/ee/lib/gitlab/auth/group_saml/sso_enforcer.rb:35:in `group_access_restricted?'*/
            GroupMember Load (3.1ms)  SELECT "members".* FROM ((SELECT "members".* FROM "members" LEFT OUTER JOIN "users" ON "members"."user_id" = "users"."id" WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "users"."state" = 'active' AND "members"."requested_at" IS NULL AND "members"."invite_token" IS NULL AND (members.access_level > 5) AND (members.access_level > 5) AND "members"."source_id" IN (WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "id" FROM "base_and_ancestors" AS "namespaces"))
          UNION
          (WITH "group_group_links_cte" AS MATERIALIZED (SELECT "group_group_links".* FROM "group_group_links" WHERE "group_group_links"."shared_group_id" IN (WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "id" FROM "base_and_ancestors" AS "namespaces")) SELECT "members"."id", LEAST("group_group_links"."group_access", "members"."access_level") AS access_level, "members"."source_id", "members"."source_type", "members"."user_id", "members"."notification_level", "members"."type", "members"."created_at", "members"."updated_at", "members"."created_by_id", "members"."invite_email", "members"."invite_token", "members"."invite_accepted_at", "members"."requested_at", "members"."expires_at", "members"."ldap", "members"."override" FROM "members", "group_group_links_cte" AS "group_group_links" WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "members"."requested_at" IS NULL AND "members"."source_id" = "group_group_links"."shared_with_group_id" AND "members"."source_type" = 'Namespace' AND (members.access_level > 5))) members WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "members"."user_id" = 92 ORDER BY "members"."access_level" DESC LIMIT 1 /*application:console,line:/app/models/group.rb:586:in `max_member_access'*/
            Project Exists? (1.5ms)  SELECT 1 AS one FROM "projects" WHERE "projects"."namespace_id" IN (WITH RECURSIVE "base_and_descendants" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_descendants" WHERE "namespaces"."type" = 'Group' AND "namespaces"."parent_id" = "base_and_descendants"."id")) SELECT "id" FROM "base_and_descendants" AS "namespaces") AND (EXISTS (SELECT 1 FROM "project_authorizations" WHERE "project_authorizations"."user_id" = 92 AND (project_authorizations.project_id = projects.id)) OR projects.visibility_level IN (10,20)) LIMIT 1 /*application:console,line:/app/policies/group_policy.rb:27:in `block in '*/
            Iteration Load (0.6ms)  SELECT "sprints".* FROM ((SELECT "sprints".* FROM "sprints" WHERE "sprints"."project_id" = 29)
          UNION ALL
          (SELECT "sprints".* FROM "sprints" WHERE "sprints"."group_id" IN (107, 108, 110))) sprints ORDER BY due_date ASC NULLS LAST, "sprints"."title" ASC /*application:console,line:/Users/acroitor/.asdf/installs/ruby/2.7.2/lib/ruby/2.7.0/pp.rb:163:in `block in pp'*/
          => [#,
           #,
           #,
           #,
           #,
           #,
           #,
           #,
           #,
           #,
           #,
           #,
           #]
        
    • fetching iterations from Group(110) level with `include_ancestors: true`
      
          [13] pry(main)> params = IterationsFinder.params_for_parent(Group.find(110), include_ancestors: true)
          Group Load (0.6ms)  SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110 LIMIT 1 /*application:console,line:(pry):13:in `__pry__'*/
            Group Load (1.2ms)  WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "id" FROM "base_and_ancestors" AS "namespaces" /*application:console,line:/Users/acroitor/.asdf/installs/ruby/2.7.2/lib/ruby/2.7.0/pp.rb:163:in `block in pp'*/
            Route Load (0.4ms)  SELECT "routes".* FROM "routes" WHERE "routes"."source_id" = 110 AND "routes"."source_type" = 'Namespace' LIMIT 1 /*application:console,line:/app/models/concerns/routable.rb:118:in `full_path'*/
            Route Load (0.3ms)  SELECT "routes".* FROM "routes" WHERE "routes"."source_id" = 108 AND "routes"."source_type" = 'Namespace' LIMIT 1 /*application:console,line:/app/models/concerns/routable.rb:118:in `full_path'*/
            Route Load (0.2ms)  SELECT "routes".* FROM "routes" WHERE "routes"."source_id" = 107 AND "routes"."source_type" = 'Namespace' LIMIT 1 /*application:console,line:/app/models/concerns/routable.rb:118:in `full_path'*/
          => {:group_ids=>[#, #, #]}
          [14] pry(main)> iterations = IterationsFinder.new(user, params).execute
            Group Load (2.1ms)  WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" IN (WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "id" FROM "base_and_ancestors" AS "namespaces"))
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT namespaces.id, namespaces.parent_id, gitlab_subscriptions.hosted_plan_id FROM "base_and_ancestors" AS "namespaces" LEFT OUTER JOIN gitlab_subscriptions ON gitlab_subscriptions.namespace_id=namespaces.id /*application:console,line:/ee/lib/gitlab/group_plans_preloader.rb:20:in `each_with_object'*/
            Plan Load (0.3ms)  SELECT "plans".* FROM "plans" WHERE 1=0 /*application:console,line:/ee/lib/gitlab/group_plans_preloader.rb:46:in `each_with_object'*/
            Group Load (1.1ms)  SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" IN (WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "id" FROM "base_and_ancestors" AS "namespaces") /*application:console,line:/ee/lib/gitlab/group_plans_preloader.rb:51:in `preload'*/
            ApplicationSetting Load (0.8ms)  SELECT "application_settings".* FROM "application_settings" ORDER BY "application_settings"."id" DESC LIMIT 1 /*application:console,line:/app/models/concerns/cacheable_attributes.rb:19:in `current_without_cache'*/
            SamlProvider Load (0.2ms)  SELECT "saml_providers".* FROM "saml_providers" WHERE "saml_providers"."group_id" = 107 LIMIT 1 /*application:console,line:/ee/lib/gitlab/auth/group_saml/sso_enforcer.rb:35:in `group_access_restricted?'*/
            GroupMember Load (1.1ms)  SELECT "members".* FROM ((SELECT "members".* FROM "members" LEFT OUTER JOIN "users" ON "members"."user_id" = "users"."id" WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "users"."state" = 'active' AND "members"."requested_at" IS NULL AND "members"."invite_token" IS NULL AND (members.access_level > 5) AND (members.access_level > 5) AND "members"."source_id" = 107)
          UNION
          (WITH "group_group_links_cte" AS MATERIALIZED (SELECT "group_group_links".* FROM "group_group_links" WHERE "group_group_links"."shared_group_id" = 107) SELECT "members"."id", LEAST("group_group_links"."group_access", "members"."access_level") AS access_level, "members"."source_id", "members"."source_type", "members"."user_id", "members"."notification_level", "members"."type", "members"."created_at", "members"."updated_at", "members"."created_by_id", "members"."invite_email", "members"."invite_token", "members"."invite_accepted_at", "members"."requested_at", "members"."expires_at", "members"."ldap", "members"."override" FROM "members", "group_group_links_cte" AS "group_group_links" WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "members"."requested_at" IS NULL AND "members"."source_id" = "group_group_links"."shared_with_group_id" AND "members"."source_type" = 'Namespace' AND (members.access_level > 5))) members WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "members"."user_id" = 92 ORDER BY "members"."access_level" DESC LIMIT 1 /*application:console,line:/app/models/group.rb:586:in `max_member_access'*/
            Project Exists? (1.5ms)  SELECT 1 AS one FROM "projects" WHERE "projects"."namespace_id" IN (WITH RECURSIVE "base_and_descendants" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 107)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_descendants" WHERE "namespaces"."type" = 'Group' AND "namespaces"."parent_id" = "base_and_descendants"."id")) SELECT "id" FROM "base_and_descendants" AS "namespaces") AND (EXISTS (SELECT 1 FROM "project_authorizations" WHERE "project_authorizations"."user_id" = 92 AND (project_authorizations.project_id = projects.id)) OR projects.visibility_level IN (10,20)) LIMIT 1 /*application:console,line:/app/policies/group_policy.rb:27:in `block in '*/
            License Load (0.2ms)  SELECT "licenses".* FROM "licenses" ORDER BY "licenses"."id" DESC LIMIT 100 /*application:console,line:/ee/app/models/license.rb:302:in `load_license'*/
            Namespace Load (0.5ms)  SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."id" = 107 LIMIT 1 /*application:console,line:/app/models/namespaces/traversal/recursive.rb:9:in `root_ancestor'*/
            Group Load (1.0ms)  WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 108)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "namespaces".* FROM "base_and_ancestors" AS "namespaces" WHERE "namespaces"."parent_id" IS NULL LIMIT 1 /*application:console,line:/app/models/namespaces/traversal/recursive.rb:13:in `block in root_ancestor'*/
            SamlProvider Load (0.2ms)  SELECT "saml_providers".* FROM "saml_providers" WHERE "saml_providers"."group_id" = 107 LIMIT 1 /*application:console,line:/ee/lib/gitlab/auth/group_saml/sso_enforcer.rb:35:in `group_access_restricted?'*/
            GroupMember Load (2.8ms)  SELECT "members".* FROM ((SELECT "members".* FROM "members" LEFT OUTER JOIN "users" ON "members"."user_id" = "users"."id" WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "users"."state" = 'active' AND "members"."requested_at" IS NULL AND "members"."invite_token" IS NULL AND (members.access_level > 5) AND (members.access_level > 5) AND "members"."source_id" IN (WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 108)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "id" FROM "base_and_ancestors" AS "namespaces"))
          UNION
          (WITH "group_group_links_cte" AS MATERIALIZED (SELECT "group_group_links".* FROM "group_group_links" WHERE "group_group_links"."shared_group_id" IN (WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 108)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "id" FROM "base_and_ancestors" AS "namespaces")) SELECT "members"."id", LEAST("group_group_links"."group_access", "members"."access_level") AS access_level, "members"."source_id", "members"."source_type", "members"."user_id", "members"."notification_level", "members"."type", "members"."created_at", "members"."updated_at", "members"."created_by_id", "members"."invite_email", "members"."invite_token", "members"."invite_accepted_at", "members"."requested_at", "members"."expires_at", "members"."ldap", "members"."override" FROM "members", "group_group_links_cte" AS "group_group_links" WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "members"."requested_at" IS NULL AND "members"."source_id" = "group_group_links"."shared_with_group_id" AND "members"."source_type" = 'Namespace' AND (members.access_level > 5))) members WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "members"."user_id" = 92 ORDER BY "members"."access_level" DESC LIMIT 1 /*application:console,line:/app/models/group.rb:586:in `max_member_access'*/
            Project Exists? (1.5ms)  SELECT 1 AS one FROM "projects" WHERE "projects"."namespace_id" IN (WITH RECURSIVE "base_and_descendants" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 108)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_descendants" WHERE "namespaces"."type" = 'Group' AND "namespaces"."parent_id" = "base_and_descendants"."id")) SELECT "id" FROM "base_and_descendants" AS "namespaces") AND (EXISTS (SELECT 1 FROM "project_authorizations" WHERE "project_authorizations"."user_id" = 92 AND (project_authorizations.project_id = projects.id)) OR projects.visibility_level IN (10,20)) LIMIT 1 /*application:console,line:/app/policies/group_policy.rb:27:in `block in '*/
            Namespace Load (0.5ms)  SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."id" = 108 LIMIT 1 /*application:console,line:/app/models/namespaces/traversal/recursive.rb:9:in `root_ancestor'*/
            Group Load (0.9ms)  WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "namespaces".* FROM "base_and_ancestors" AS "namespaces" WHERE "namespaces"."parent_id" IS NULL LIMIT 1 /*application:console,line:/app/models/namespaces/traversal/recursive.rb:13:in `block in root_ancestor'*/
            SamlProvider Load (0.3ms)  SELECT "saml_providers".* FROM "saml_providers" WHERE "saml_providers"."group_id" = 107 LIMIT 1 /*application:console,line:/ee/lib/gitlab/auth/group_saml/sso_enforcer.rb:35:in `group_access_restricted?'*/
            GroupMember Load (2.8ms)  SELECT "members".* FROM ((SELECT "members".* FROM "members" LEFT OUTER JOIN "users" ON "members"."user_id" = "users"."id" WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "users"."state" = 'active' AND "members"."requested_at" IS NULL AND "members"."invite_token" IS NULL AND (members.access_level > 5) AND (members.access_level > 5) AND "members"."source_id" IN (WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "id" FROM "base_and_ancestors" AS "namespaces"))
          UNION
          (WITH "group_group_links_cte" AS MATERIALIZED (SELECT "group_group_links".* FROM "group_group_links" WHERE "group_group_links"."shared_group_id" IN (WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "id" FROM "base_and_ancestors" AS "namespaces")) SELECT "members"."id", LEAST("group_group_links"."group_access", "members"."access_level") AS access_level, "members"."source_id", "members"."source_type", "members"."user_id", "members"."notification_level", "members"."type", "members"."created_at", "members"."updated_at", "members"."created_by_id", "members"."invite_email", "members"."invite_token", "members"."invite_accepted_at", "members"."requested_at", "members"."expires_at", "members"."ldap", "members"."override" FROM "members", "group_group_links_cte" AS "group_group_links" WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "members"."requested_at" IS NULL AND "members"."source_id" = "group_group_links"."shared_with_group_id" AND "members"."source_type" = 'Namespace' AND (members.access_level > 5))) members WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "members"."user_id" = 92 ORDER BY "members"."access_level" DESC LIMIT 1 /*application:console,line:/app/models/group.rb:586:in `max_member_access'*/
            Project Exists? (1.8ms)  SELECT 1 AS one FROM "projects" WHERE "projects"."namespace_id" IN (WITH RECURSIVE "base_and_descendants" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_descendants" WHERE "namespaces"."type" = 'Group' AND "namespaces"."parent_id" = "base_and_descendants"."id")) SELECT "id" FROM "base_and_descendants" AS "namespaces") AND (EXISTS (SELECT 1 FROM "project_authorizations" WHERE "project_authorizations"."user_id" = 92 AND (project_authorizations.project_id = projects.id)) OR projects.visibility_level IN (10,20)) LIMIT 1 /*application:console,line:/app/policies/group_policy.rb:27:in `block in '*/
            Iteration Load (0.6ms)  SELECT "sprints".* FROM ((SELECT "sprints".* FROM "sprints" WHERE 1=0)
          UNION ALL
          (SELECT "sprints".* FROM "sprints" WHERE "sprints"."group_id" IN (107, 108, 110))) sprints ORDER BY due_date ASC NULLS LAST, "sprints"."title" ASC /*application:console,line:/Users/acroitor/.asdf/installs/ruby/2.7.2/lib/ruby/2.7.0/pp.rb:163:in `block in pp'*/
          => [#,
           #,
           #,
           #,
           #,
           #,
           #,
           #,
           #,
           #,
           #,
           #,
           #]
          [15] pry(main)> iterations = IterationsFinder.new(user, params).execute
            Group Load (1.3ms)  WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" IN (107, 108, 110))
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT namespaces.id, namespaces.parent_id, gitlab_subscriptions.hosted_plan_id FROM "base_and_ancestors" AS "namespaces" LEFT OUTER JOIN gitlab_subscriptions ON gitlab_subscriptions.namespace_id=namespaces.id /*application:console,line:/ee/lib/gitlab/group_plans_preloader.rb:20:in `each_with_object'*/
            Plan Load (0.3ms)  SELECT "plans".* FROM "plans" WHERE 1=0 /*application:console,line:/ee/lib/gitlab/group_plans_preloader.rb:46:in `each_with_object'*/
            Group Load (0.5ms)  SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" IN (107, 108, 110) /*application:console,line:/ee/lib/gitlab/group_plans_preloader.rb:51:in `preload'*/
            SamlProvider Load (0.4ms)  SELECT "saml_providers".* FROM "saml_providers" WHERE "saml_providers"."group_id" = 107 LIMIT 1 /*application:console,line:/ee/lib/gitlab/auth/group_saml/sso_enforcer.rb:35:in `group_access_restricted?'*/
            GroupMember Load (1.2ms)  SELECT "members".* FROM ((SELECT "members".* FROM "members" LEFT OUTER JOIN "users" ON "members"."user_id" = "users"."id" WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "users"."state" = 'active' AND "members"."requested_at" IS NULL AND "members"."invite_token" IS NULL AND (members.access_level > 5) AND (members.access_level > 5) AND "members"."source_id" = 107)
          UNION
          (WITH "group_group_links_cte" AS MATERIALIZED (SELECT "group_group_links".* FROM "group_group_links" WHERE "group_group_links"."shared_group_id" = 107) SELECT "members"."id", LEAST("group_group_links"."group_access", "members"."access_level") AS access_level, "members"."source_id", "members"."source_type", "members"."user_id", "members"."notification_level", "members"."type", "members"."created_at", "members"."updated_at", "members"."created_by_id", "members"."invite_email", "members"."invite_token", "members"."invite_accepted_at", "members"."requested_at", "members"."expires_at", "members"."ldap", "members"."override" FROM "members", "group_group_links_cte" AS "group_group_links" WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "members"."requested_at" IS NULL AND "members"."source_id" = "group_group_links"."shared_with_group_id" AND "members"."source_type" = 'Namespace' AND (members.access_level > 5))) members WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "members"."user_id" = 92 ORDER BY "members"."access_level" DESC LIMIT 1 /*application:console,line:/app/models/group.rb:586:in `max_member_access'*/
            Project Exists? (1.5ms)  SELECT 1 AS one FROM "projects" WHERE "projects"."namespace_id" IN (WITH RECURSIVE "base_and_descendants" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 107)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_descendants" WHERE "namespaces"."type" = 'Group' AND "namespaces"."parent_id" = "base_and_descendants"."id")) SELECT "id" FROM "base_and_descendants" AS "namespaces") AND (EXISTS (SELECT 1 FROM "project_authorizations" WHERE "project_authorizations"."user_id" = 92 AND (project_authorizations.project_id = projects.id)) OR projects.visibility_level IN (10,20)) LIMIT 1 /*application:console,line:/app/policies/group_policy.rb:27:in `block in '*/
            Namespace Load (0.6ms)  SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."id" = 107 LIMIT 1 /*application:console,line:/app/models/namespaces/traversal/recursive.rb:9:in `root_ancestor'*/
            Group Load (1.2ms)  WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 108)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "namespaces".* FROM "base_and_ancestors" AS "namespaces" WHERE "namespaces"."parent_id" IS NULL LIMIT 1 /*application:console,line:/app/models/namespaces/traversal/recursive.rb:13:in `block in root_ancestor'*/
            SamlProvider Load (0.3ms)  SELECT "saml_providers".* FROM "saml_providers" WHERE "saml_providers"."group_id" = 107 LIMIT 1 /*application:console,line:/ee/lib/gitlab/auth/group_saml/sso_enforcer.rb:35:in `group_access_restricted?'*/
            GroupMember Load (4.0ms)  SELECT "members".* FROM ((SELECT "members".* FROM "members" LEFT OUTER JOIN "users" ON "members"."user_id" = "users"."id" WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "users"."state" = 'active' AND "members"."requested_at" IS NULL AND "members"."invite_token" IS NULL AND (members.access_level > 5) AND (members.access_level > 5) AND "members"."source_id" IN (WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 108)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "id" FROM "base_and_ancestors" AS "namespaces"))
          UNION
          (WITH "group_group_links_cte" AS MATERIALIZED (SELECT "group_group_links".* FROM "group_group_links" WHERE "group_group_links"."shared_group_id" IN (WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 108)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "id" FROM "base_and_ancestors" AS "namespaces")) SELECT "members"."id", LEAST("group_group_links"."group_access", "members"."access_level") AS access_level, "members"."source_id", "members"."source_type", "members"."user_id", "members"."notification_level", "members"."type", "members"."created_at", "members"."updated_at", "members"."created_by_id", "members"."invite_email", "members"."invite_token", "members"."invite_accepted_at", "members"."requested_at", "members"."expires_at", "members"."ldap", "members"."override" FROM "members", "group_group_links_cte" AS "group_group_links" WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "members"."requested_at" IS NULL AND "members"."source_id" = "group_group_links"."shared_with_group_id" AND "members"."source_type" = 'Namespace' AND (members.access_level > 5))) members WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "members"."user_id" = 92 ORDER BY "members"."access_level" DESC LIMIT 1 /*application:console,line:/app/models/group.rb:586:in `max_member_access'*/
            Project Exists? (1.7ms)  SELECT 1 AS one FROM "projects" WHERE "projects"."namespace_id" IN (WITH RECURSIVE "base_and_descendants" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 108)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_descendants" WHERE "namespaces"."type" = 'Group' AND "namespaces"."parent_id" = "base_and_descendants"."id")) SELECT "id" FROM "base_and_descendants" AS "namespaces") AND (EXISTS (SELECT 1 FROM "project_authorizations" WHERE "project_authorizations"."user_id" = 92 AND (project_authorizations.project_id = projects.id)) OR projects.visibility_level IN (10,20)) LIMIT 1 /*application:console,line:/app/policies/group_policy.rb:27:in `block in '*/
            Namespace Load (0.5ms)  SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."id" = 108 LIMIT 1 /*application:console,line:/app/models/namespaces/traversal/recursive.rb:9:in `root_ancestor'*/
            Group Load (1.0ms)  WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "namespaces".* FROM "base_and_ancestors" AS "namespaces" WHERE "namespaces"."parent_id" IS NULL LIMIT 1 /*application:console,line:/app/models/namespaces/traversal/recursive.rb:13:in `block in root_ancestor'*/
            SamlProvider Load (0.2ms)  SELECT "saml_providers".* FROM "saml_providers" WHERE "saml_providers"."group_id" = 107 LIMIT 1 /*application:console,line:/ee/lib/gitlab/auth/group_saml/sso_enforcer.rb:35:in `group_access_restricted?'*/
            GroupMember Load (3.4ms)  SELECT "members".* FROM ((SELECT "members".* FROM "members" LEFT OUTER JOIN "users" ON "members"."user_id" = "users"."id" WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "users"."state" = 'active' AND "members"."requested_at" IS NULL AND "members"."invite_token" IS NULL AND (members.access_level > 5) AND (members.access_level > 5) AND "members"."source_id" IN (WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "id" FROM "base_and_ancestors" AS "namespaces"))
          UNION
          (WITH "group_group_links_cte" AS MATERIALIZED (SELECT "group_group_links".* FROM "group_group_links" WHERE "group_group_links"."shared_group_id" IN (WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "id" FROM "base_and_ancestors" AS "namespaces")) SELECT "members"."id", LEAST("group_group_links"."group_access", "members"."access_level") AS access_level, "members"."source_id", "members"."source_type", "members"."user_id", "members"."notification_level", "members"."type", "members"."created_at", "members"."updated_at", "members"."created_by_id", "members"."invite_email", "members"."invite_token", "members"."invite_accepted_at", "members"."requested_at", "members"."expires_at", "members"."ldap", "members"."override" FROM "members", "group_group_links_cte" AS "group_group_links" WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "members"."requested_at" IS NULL AND "members"."source_id" = "group_group_links"."shared_with_group_id" AND "members"."source_type" = 'Namespace' AND (members.access_level > 5))) members WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "members"."user_id" = 92 ORDER BY "members"."access_level" DESC LIMIT 1 /*application:console,line:/app/models/group.rb:586:in `max_member_access'*/
            Project Exists? (1.6ms)  SELECT 1 AS one FROM "projects" WHERE "projects"."namespace_id" IN (WITH RECURSIVE "base_and_descendants" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_descendants" WHERE "namespaces"."type" = 'Group' AND "namespaces"."parent_id" = "base_and_descendants"."id")) SELECT "id" FROM "base_and_descendants" AS "namespaces") AND (EXISTS (SELECT 1 FROM "project_authorizations" WHERE "project_authorizations"."user_id" = 92 AND (project_authorizations.project_id = projects.id)) OR projects.visibility_level IN (10,20)) LIMIT 1 /*application:console,line:/app/policies/group_policy.rb:27:in `block in '*/
            Iteration Load (0.6ms)  SELECT "sprints".* FROM ((SELECT "sprints".* FROM "sprints" WHERE 1=0)
          UNION ALL
          (SELECT "sprints".* FROM "sprints" WHERE "sprints"."group_id" IN (107, 108, 110))) sprints ORDER BY due_date ASC NULLS LAST, "sprints"."title" ASC /*application:console,line:/Users/acroitor/.asdf/installs/ruby/2.7.2/lib/ruby/2.7.0/pp.rb:163:in `block in pp'*/
          => [#,
           #,
           #,
           #,
           #,
           #,
           #,
           #,
           #,
           #,
           #,
           #,
           #]
  • after change
    • fetching iterations from Project(29) level with `include_ancestors
      
          [4] pry(main)> params = {parent: Project.find(29), include_ancestors: true}
          Project Load (1.1ms)  SELECT "projects".* FROM "projects" WHERE "projects"."id" = 29 LIMIT 1 /*application:console,line:(pry):4:in `__pry__'*/
            Route Load (1.6ms)  SELECT "routes".* FROM "routes" WHERE "routes"."source_id" = 29 AND "routes"."source_type" = 'Project' LIMIT 1 /*application:console,line:/app/models/concerns/routable.rb:118:in `full_path'*/
          => {:parent=>#>, :include_ancestors=>true}
          [5] pry(main)> iterations = IterationsFinder.new(user, params).execute
            ProjectFeature Load (1.3ms)  SELECT "project_features".* FROM "project_features" WHERE "project_features"."project_id" = 29 LIMIT 1 /*application:console,line:/app/policies/project_policy.rb:722:in `access_allowed_to?'*/
            Group Load (3.7ms)  SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110 AND "namespaces"."type" = 'Group' LIMIT 1 /*application:console,line:/ee/app/policies/ee/project_policy.rb:307:in `block (2 levels) in '*/
            Namespace Load (0.4ms)  SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."id" = 108 LIMIT 1 /*application:console,line:/app/models/namespaces/traversal/recursive.rb:9:in `root_ancestor'*/
            Group Load (1.7ms)  WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "namespaces".* FROM "base_and_ancestors" AS "namespaces" WHERE "namespaces"."parent_id" IS NULL LIMIT 1 /*application:console,line:/app/models/namespaces/traversal/recursive.rb:13:in `block in root_ancestor'*/
            SamlProvider Load (0.9ms)  SELECT "saml_providers".* FROM "saml_providers" WHERE "saml_providers"."group_id" = 107 LIMIT 1 /*application:console,line:/ee/lib/gitlab/auth/group_saml/sso_enforcer.rb:35:in `group_access_restricted?'*/
             (1.7ms)  SELECT MAX("project_authorizations"."access_level") AS maximum_access_level, "project_authorizations"."user_id" AS project_authorizations_user_id FROM "project_authorizations" WHERE "project_authorizations"."project_id" = 29 AND "project_authorizations"."user_id" = 92 GROUP BY "project_authorizations"."user_id" /*application:console,line:/app/models/project_team.rb:173:in `block in max_member_access_for_user_ids'*/
            Namespace Load (0.5ms)  SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."id" = 110 LIMIT 1 /*application:console,line:/ee/app/finders/iterations_finder.rb:98:in `groups'*/
            Iteration Load (3.9ms)  SELECT "sprints".* FROM "sprints" WHERE "sprints"."group_id" IN (WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "namespaces"."id" FROM "base_and_ancestors" AS "namespaces") ORDER BY due_date ASC NULLS LAST, "sprints"."title" ASC /*application:console,line:/Users/acroitor/.asdf/installs/ruby/2.7.2/lib/ruby/2.7.0/pp.rb:163:in `block in pp'*/
          => [#,
           #,
           #,
           #,
           #,
           #,
           #,
           #,
           #,
           #,
           #,
           #,
           #]
          [6] pry(main)> iterations = IterationsFinder.new(user, params).execute
            ApplicationSetting Load (3.3ms)  SELECT "application_settings".* FROM "application_settings" ORDER BY "application_settings"."id" DESC LIMIT 1 /*application:console,line:/app/models/concerns/cacheable_attributes.rb:19:in `current_without_cache'*/
             (0.3ms)  SELECT MAX("project_authorizations"."access_level") AS maximum_access_level, "project_authorizations"."user_id" AS project_authorizations_user_id FROM "project_authorizations" WHERE "project_authorizations"."project_id" = 29 AND "project_authorizations"."user_id" = 92 GROUP BY "project_authorizations"."user_id" /*application:console,line:/app/models/project_team.rb:173:in `block in max_member_access_for_user_ids'*/
            Iteration Load (1.4ms)  SELECT "sprints".* FROM "sprints" WHERE "sprints"."group_id" IN (WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "namespaces"."id" FROM "base_and_ancestors" AS "namespaces") ORDER BY due_date ASC NULLS LAST, "sprints"."title" ASC /*application:console,line:/Users/acroitor/.asdf/installs/ruby/2.7.2/lib/ruby/2.7.0/pp.rb:163:in `block in pp'*/
          => [#,
           #,
           #,
           #,
           #,
           #,
           #,
           #,
           #,
           #,
           #,
           #,
           #]
    • fetching iterations from Group(110) level with `include_ancestors: true`
      
          [8] pry(main)> params = {parent: Group.find(110), include_ancestors: true}
          Group Load (0.7ms)  SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110 LIMIT 1 /*application:console,line:(pry):8:in `__pry__'*/
            Route Load (0.5ms)  SELECT "routes".* FROM "routes" WHERE "routes"."source_id" = 110 AND "routes"."source_type" = 'Namespace' LIMIT 1 /*application:console,line:/app/models/concerns/routable.rb:118:in `full_path'*/
          => {:parent=>#, :include_ancestors=>true}
          [9] pry(main)> iterations = IterationsFinder.new(user, params).execute
            Namespace Load (0.5ms)  SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."id" = 108 LIMIT 1 /*application:console,line:/app/models/namespaces/traversal/recursive.rb:9:in `root_ancestor'*/
            Group Load (1.1ms)  WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "namespaces".* FROM "base_and_ancestors" AS "namespaces" WHERE "namespaces"."parent_id" IS NULL LIMIT 1 /*application:console,line:/app/models/namespaces/traversal/recursive.rb:13:in `block in root_ancestor'*/
            SamlProvider Load (0.2ms)  SELECT "saml_providers".* FROM "saml_providers" WHERE "saml_providers"."group_id" = 107 LIMIT 1 /*application:console,line:/ee/lib/gitlab/auth/group_saml/sso_enforcer.rb:35:in `group_access_restricted?'*/
            GroupMember Load (6.4ms)  SELECT "members".* FROM ((SELECT "members".* FROM "members" LEFT OUTER JOIN "users" ON "members"."user_id" = "users"."id" WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "users"."state" = 'active' AND "members"."requested_at" IS NULL AND "members"."invite_token" IS NULL AND (members.access_level > 5) AND (members.access_level > 5) AND "members"."source_id" IN (WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "id" FROM "base_and_ancestors" AS "namespaces"))
          UNION
          (WITH "group_group_links_cte" AS MATERIALIZED (SELECT "group_group_links".* FROM "group_group_links" WHERE "group_group_links"."shared_group_id" IN (WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "id" FROM "base_and_ancestors" AS "namespaces")) SELECT "members"."id", LEAST("group_group_links"."group_access", "members"."access_level") AS access_level, "members"."source_id", "members"."source_type", "members"."user_id", "members"."notification_level", "members"."type", "members"."created_at", "members"."updated_at", "members"."created_by_id", "members"."invite_email", "members"."invite_token", "members"."invite_accepted_at", "members"."requested_at", "members"."expires_at", "members"."ldap", "members"."override" FROM "members", "group_group_links_cte" AS "group_group_links" WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "members"."requested_at" IS NULL AND "members"."source_id" = "group_group_links"."shared_with_group_id" AND "members"."source_type" = 'Namespace' AND (members.access_level > 5))) members WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "members"."user_id" = 92 ORDER BY "members"."access_level" DESC LIMIT 1 /*application:console,line:/app/models/group.rb:586:in `max_member_access'*/
            Project Exists? (1.6ms)  SELECT 1 AS one FROM "projects" WHERE "projects"."namespace_id" IN (WITH RECURSIVE "base_and_descendants" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_descendants" WHERE "namespaces"."type" = 'Group' AND "namespaces"."parent_id" = "base_and_descendants"."id")) SELECT "id" FROM "base_and_descendants" AS "namespaces") AND (EXISTS (SELECT 1 FROM "project_authorizations" WHERE "project_authorizations"."user_id" = 92 AND (project_authorizations.project_id = projects.id)) OR projects.visibility_level IN (10,20)) LIMIT 1 /*application:console,line:/app/policies/group_policy.rb:27:in `block in '*/
            License Load (0.5ms)  SELECT "licenses".* FROM "licenses" ORDER BY "licenses"."id" DESC LIMIT 100 /*application:console,line:/ee/app/models/license.rb:302:in `load_license'*/
            Iteration Load (1.3ms)  SELECT "sprints".* FROM "sprints" WHERE "sprints"."group_id" IN (WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "namespaces"."id" FROM "base_and_ancestors" AS "namespaces") ORDER BY due_date ASC NULLS LAST, "sprints"."title" ASC /*application:console,line:/Users/acroitor/.asdf/installs/ruby/2.7.2/lib/ruby/2.7.0/pp.rb:163:in `block in pp'*/
          => [#,
           #,
           #,
           #,
           #,
           #,
           #,
           #,
           #,
           #,
           #,
           #,
           #]
          [10] pry(main)> iterations = IterationsFinder.new(user, params).execute
            GroupMember Load (3.5ms)  SELECT "members".* FROM ((SELECT "members".* FROM "members" LEFT OUTER JOIN "users" ON "members"."user_id" = "users"."id" WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "users"."state" = 'active' AND "members"."requested_at" IS NULL AND "members"."invite_token" IS NULL AND (members.access_level > 5) AND (members.access_level > 5) AND "members"."source_id" IN (WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "id" FROM "base_and_ancestors" AS "namespaces"))
          UNION
          (WITH "group_group_links_cte" AS MATERIALIZED (SELECT "group_group_links".* FROM "group_group_links" WHERE "group_group_links"."shared_group_id" IN (WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "id" FROM "base_and_ancestors" AS "namespaces")) SELECT "members"."id", LEAST("group_group_links"."group_access", "members"."access_level") AS access_level, "members"."source_id", "members"."source_type", "members"."user_id", "members"."notification_level", "members"."type", "members"."created_at", "members"."updated_at", "members"."created_by_id", "members"."invite_email", "members"."invite_token", "members"."invite_accepted_at", "members"."requested_at", "members"."expires_at", "members"."ldap", "members"."override" FROM "members", "group_group_links_cte" AS "group_group_links" WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "members"."requested_at" IS NULL AND "members"."source_id" = "group_group_links"."shared_with_group_id" AND "members"."source_type" = 'Namespace' AND (members.access_level > 5))) members WHERE "members"."type" = 'GroupMember' AND "members"."source_type" = 'Namespace' AND "members"."user_id" = 92 ORDER BY "members"."access_level" DESC LIMIT 1 /*application:console,line:/app/models/group.rb:586:in `max_member_access'*/
            Project Exists? (2.1ms)  SELECT 1 AS one FROM "projects" WHERE "projects"."namespace_id" IN (WITH RECURSIVE "base_and_descendants" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_descendants" WHERE "namespaces"."type" = 'Group' AND "namespaces"."parent_id" = "base_and_descendants"."id")) SELECT "id" FROM "base_and_descendants" AS "namespaces") AND (EXISTS (SELECT 1 FROM "project_authorizations" WHERE "project_authorizations"."user_id" = 92 AND (project_authorizations.project_id = projects.id)) OR projects.visibility_level IN (10,20)) LIMIT 1 /*application:console,line:/app/policies/group_policy.rb:27:in `block in '*/
            Iteration Load (1.5ms)  SELECT "sprints".* FROM "sprints" WHERE "sprints"."group_id" IN (WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 110)
          UNION
          (SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT "namespaces"."id" FROM "base_and_ancestors" AS "namespaces") ORDER BY due_date ASC NULLS LAST, "sprints"."title" ASC /*application:console,line:/Users/acroitor/.asdf/installs/ruby/2.7.2/lib/ruby/2.7.0/pp.rb:163:in `block in pp'*/
          => [#,
           #,
           #,
           #,
           #,
           #,
           #,
           #,
           #,
           #,
           #,
           #,
           #]
          [11] pry(main)>
        

Partly related to a follow-up #293686 (closed) in the sense that the follow-up drove the investigation to the change

Screenshots (strongly suggested)

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 Alexandru Croitor

Merge request reports