Optimize API /groups/:id/projects by preloading assocations
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)