Skip to content

GitLab Next

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
GitLab FOSS
GitLab FOSS
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 0
    • Merge Requests 0
  • Requirements
    • Requirements
    • List
  • Security & Compliance
    • Security & Compliance
    • Dependency List
    • License Compliance
  • Operations
    • Operations
    • Incidents
    • Environments
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
  • GitLab.org
  • GitLab FOSSGitLab FOSS
  • Merge Requests
  • !15475

Merged
Opened Nov 19, 2017 by Stan Hu@stanhuOwner9 of 9 tasks completed9/9 tasks

Optimize API /groups/:id/projects by preloading assocations

  • Overview 51
  • Commits 21
  • Pipelines 28
  • Changes 18

There are a number of N+1 queries:

  • Project#namespace: https://gitlab.com/gitlab-org/gitlab-ee/blob/v10.1.3-ee/lib/api/entities.rb#L158
  • Project#group: https://gitlab.com/gitlab-org/gitlab-ee/blob/v10.1.3-ee/lib/api/entities.rb#L144
  • Project#feature_available?: https://gitlab.com/gitlab-org/gitlab-ee/blob/v10.1.3-ee/lib/api/entities.rb#L149
  • Project#forked?: https://gitlab.com/gitlab-org/gitlab-ee/blob/v10.1.3-ee/lib/api/entities.rb#L159
  • Project#project_group_links: https://gitlab.com/gitlab-org/gitlab-ee/blob/v10.1.3-ee/lib/api/entities.rb#L168
  • Project#route: via https://gitlab.com/gitlab-org/gitlab-ee/blob/v10.1.3-ee/lib/api/entities.rb#L98
  • Project#forks_count: https://gitlab.com/gitlab-org/gitlab-ee/blob/v10.1.3-ee/lib/api/entities.rb#L105
SELECT COUNT(*) FROM "projects" INNER JOIN "forked_project_links" ON "projects"."id" = "forked_project_links"."forked_to_project_id" WHERE "forked_project_links"."forked_from_project_id" = $1 AND ("projects"."pending_delete" != $2)
  • Project#tag_list: https://gitlab.com/gitlab-org/gitlab-ee/blob/v10.1.3-ee/lib/api/entities.rb#L98, https://github.com/mbleigh/acts-as-taggable-on/blob/v4.0.0/lib/acts_as_taggable_on/taggable/core.rb#L289. Looks related to https://github.com/mbleigh/acts-as-taggable-on/issues/91#issuecomment-168273770
SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = $1 AND "taggings"."taggable_type" = $2 AND (taggings.context = 'tags' AND taggings.tagger_id IS NULL)
  • Project#open_issues_count: https://gitlab.com/gitlab-org/gitlab-ee/blob/v10.1.3-ee/lib/api/entities.rb#L163
SELECT COUNT(*) FROM "issues" WHERE "issues"."deleted_at" IS NULL AND "issues"."project_id" = $1 AND ("issues"."state" IN ('opened')) AND "issues"."confidential" = $2

See http://profiler.gitlap.com/20171119/6caac0fe-04a6-4b91-9d75-0c887489f426.txt.gz for a sample dump.

Closes #40308 (closed)

Edited Nov 24, 2017 by Francisco Javier López
Assignee
Assign to
Reviewer
Request review from
10.2
Milestone
10.2 (Past due)
Assign milestone
Time tracking
Reference: gitlab-org/gitlab-foss!15475
Source branch: sh-optimize-groups-api

Revert this merge request

This will create a new commit in order to revert the existing changes.

Switch branch
Cancel
A new branch will be created in your fork and a new merge request will be started.

Cherry-pick this merge request

Switch branch
Cancel
A new branch will be created in your fork and a new merge request will be started.